programing

JSON을 통해 JSON의 가치를 얻습니다.그물

fastcode 2023. 4. 5. 22:18
반응형

JSON을 통해 JSON의 가치를 얻습니다.그물

http://www.codeplex.com/Json을 사용하여 json 객체에서 값을 추출하려고 합니다.

imdbapi.com을 사용하면 다음과 같이 json이 반환됩니다.

{"Title": "Star Wars", "Year": "1977", "Rated", "PG", "Released", "25 May 1977", "Genre", "Action, Adventure, Fantasy, Sci-Fi "" Director ":" George Lucas "," Writer "," George Lucas "," Actors ":" Mark Hamill, Harrison Ford, Carrie Fisher, Alec Guinness, "" Plot ":" Luke Skywalker leaves his home planet, teams up With Other Rebels, and Tries to save Princess Leia from the evil clutch of Darth hrs 1 min "," Rating ":" 8.8 "," Votes ":" 397318 "," ID ":" tt0076759 "," Response ":" True "}

이러한 제목, 등급, 연도를 선택하여 내 개체에 저장하려면 어떻게 해야 합니까?

다음 행은 올바른 json을 반환합니다.

JObject jObject = JObject.Parse (json);

이제 원하는 데이터를 고르는 데 도움이 필요합니다.좋은 의견이라도 있나?

http://james.newtonking.com/pages/json-net.aspx 를 참조해 주세요.

string json = @"{
    ""Name"": ""Apple"",
    ""Expiry"": new Date(1230422400000),
    ""Price"": 3.99,
    ""Sizes"": [
        ""Small"",
        ""Medium"",
        ""Large""
    ]
}";

JObject o = JObject.Parse(json);

//This will be "Apple"
string name = (string)o["Name"];

JObject API 문서

에 관심이 있으시리라 믿습니다.JToken을 반환하는 항목[키] 컬렉션.

완전한 문서

class TypeHere{
   string Name {get;set;}
}

TypeHere object = JsonConvert.DeserializeObject< TypeHere >(jsonString)

// Ex. output 
object.Name;

언급URL : https://stackoverflow.com/questions/9010021/get-value-from-json-with-json-net

반응형