2012-01-25 25 views
22

Provo ad utilizzare http://www.codeplex.com/Json per estrarre i valori da un oggetto json.Ottieni il valore da JSON con JSON.NET

Io uso imdbapi.com e tornano JSON in questo modo:

{"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 "} 

Come posso ritirare tale titolo, rating, Anno? e salvarlo sul mio oggetto?

Questa linea di ritorno corretto JSON:

JObject jObject = JObject.Parse (json); 

Ora ho solo bisogno di aiuto individuando i dati che voglio. eventuali suggerimenti?

risposta

54

Questo dovrebbe aiutare a 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"]; 
Problemi correlati