2012-01-25 46 views
22

Intento usar http://www.codeplex.com/Json para extraer valores de un objeto json.Obtener el valor de JSON con JSON.NET

utilizo imdbapi.com y regresan JSON como esto:

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

¿Cómo puedo recoger a tal título, clasificación, Año? y guardarlo en mi objeto?

Esta línea de retorno JSON correcta:

JObject jObject = JObject.Parse (json); 

Ahora sólo necesitan ayuda para escoger los datos que yo quiero. ¿alguna sugerencia?

Respuesta

54

Esto debería ayudarle 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"]; 
Cuestiones relacionadas