2012-01-25 4 views
22

http://www.codeplex.com/Json을 사용하여 json 개체에서 값을 추출하려고합니다.JSON.NET을 사용하여 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); 

지금 난 그냥 내가 원하는 데이터를 따기 도움이 필요합니다. 어떤 제안?

답변

54

이것은 당신이 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"];