Get value from JSON with JSON.NET

I try to use http://www.codeplex.com/Json to extract values ​​from a json object.

I use imdbapi.com and they return json like this:

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

How can I pick up such title, rating, Year? and save it to my object?

This line return correct json:

JObject jObject = JObject.Parse (json);

Now I just need help picking out the data I want. any suggestions?


Solution 1:

This should help you 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"];

Solution 2:

JObject API documentation

I believe you are interested in the .Item[key] collection that returns JTokens.

Full Documentation

Solution 3:

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

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

// Ex. output 
object.Name;