我必须从json中检索特定值。例如:字符串格式中的“id”:“217331368373746”。 下面是json查询,我的代码为acess id = 217331368373746
{
"id": "191746304265586",
"albums": {
"data": [
{
"id": "217331368373746",
"created_time": "2012-03-24T20:53:34+0000"
}
],
"paging": {
"next": "https://graph.facebook.com/191746304265586/albums?limit=1&fields=id&after=MjE3MzMxMzY4MzczNzQ2"
}
}
}
CODE:
var jsonalbum = Retrivedata("https://graph.facebook.com/191746304265586?fields=albums.limit(1).fields(id)");
foreach (var objalbum in jsonalbum["albums"])
{
//here what code
}
public dynamic Retrivedata(string query)
{
var request = WebRequest.Create(query);
var twitpicResponse = (HttpWebResponse)request.GetResponse();
var reader = new StreamReader(twitpicResponse.GetResponseStream());
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Deserialize<dynamic>(reader.ReadToEnd());
}
答案 0 :(得分:1)
看起来像
foreach (var objalbum in jsonalbum["albums"]["data"])
{
var id = objalbum["id"]
}
答案 1 :(得分:0)
您的data
列表中似乎还有albums
属性(数组),所以您必须这样做:
foreach (var objalbum in jsonalbum["albums"]["data"])
{
var id = objalbum["id"];
...
}