使用JSON.NET从JSON获取价值 [英] Get value from JSON with JSON.NET
本文介绍了使用JSON.NET从JSON获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用 http://www.codeplex.com/Json 提取值来自json对象.
I try to use http://www.codeplex.com/Json to extract values from a json object.
我使用imdbapi.com,它们返回的json如下:
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?
此行返回正确的json:
This line return correct json:
JObject jObject = JObject.Parse (json);
现在,我只需要帮助挑选所需的数据即可.有什么建议吗?
Now I just need help picking out the data I want. any suggestions?
推荐答案
这应该可以帮助您 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"];
这篇关于使用JSON.NET从JSON获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文