40

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?

3 Answers 3

84

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"];
Sign up to request clarification or add additional context in comments.

1 Comment

You should test if the key : o.ContainsKey("Name")
4

JObject API documentation

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

Full Documentation

Comments

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

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

// Ex. output 
object.Name;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.