【发布时间】:2014-02-21 06:29:51
【问题描述】:
我从 twitter 获得以下输出,我只想从输出中捕获以下详细信息。
- 屏幕名称
- 关注人数
- profile_image_url
问题是数据在嵌套的 Json 中。
Twitter API 输出:
[{ "contributors" : null,
"coordinates" : null,
"created_at" : "Wed Jan 29 09:18:15 +0000 2014",
"favorite_count" : 0,
"favorited" : false,
"geo" : null,
"id" : 428457050109382657,
"id_str" : "428457050109382657",
"in_reply_to_screen_name" : null,
"in_reply_to_status_id" : null,
"in_reply_to_status_id_str" : null,
"in_reply_to_user_id" : null,
"in_reply_to_user_id_str" : null,
"lang" : "en",
"place" : null,
"user" : { "contributors_enabled" : false,
"follow_request_sent" : null,
"followers_count" : 218,
"id" : 609465835,
"id_str" : "609465835",
"is_translation_enabled" : false,
"is_translator" : false,
"lang" : "en",
"listed_count" : 3,
"location" : "Still alpha as hell.",
"verified" : false
}
},
{ "contributors" : null,
"coordinates" : null,
"created_at" : "Wed Jan 29 09:18:15 +0000 2014",
"favorite_count" : 0,
"favorited" : false,
"geo" : null,
"id" : 428457050109382657,
"id_str" : "428457050109382657",
"in_reply_to_screen_name" : null,
"in_reply_to_status_id" : null,
"in_reply_to_status_id_str" : null,
"in_reply_to_user_id" : null,
"in_reply_to_user_id_str" : null,
"lang" : "en",
"place" : null,
"user" : { "contributors_enabled" : false,
"follow_request_sent" : null,
"followers_count" : 1218,
"id" :33333,
"id_str" : "609465835",
"is_translation_enabled" : false,
"is_translator" : false,
"lang" : "en",
"listed_count" : 3,
"location" : "N",
"verified" : false
}
}]
输出是
我正在尝试使用 Newtonsoft Json 反序列化,但失败了。
以下是代码:
dynamic dynObj = JsonConvert.DeserializeObject(twitAuthResponse);
foreach (var data in dynObj.user.data)
{
//Console.WriteLine("{0}", data.name);
foreach (var fql in data.user)
{
foreach (JProperty keyValue in fql)
{
Console.WriteLine("\t{0} : {1}", keyValue.Name, keyValue.Value);
}
}
}
以上代码返回错误“'Newtonsoft.Json.Linq.JArray'不包含'user'的定义”。
有人可以帮我吗?提前致谢!
【问题讨论】: