使用 JSON.Net ( http://www.newtonsoft.com/json/help/html/LINQtoJSON.htm ) 和以下代码:
@using Newtonsoft.Json;
@using Newtonsoft.Json.Linq;
@{
var url = "https://graph.facebook.com/v2.2/me&fields=id%2Cname%2Cposts.limit(3)&format=json&method=get&pretty=0&suppress_http_code=1";
var syncClient = new WebClient();
var content = syncClient.DownloadString(url);
JObject facebook = JObject.Parse(content);
//To-Do: Get all messages as list<string> using LINQ for JSON
// Ex: IList<string> allDrives = o["Drives"].Select(t => (string)t).ToList();
}
在给定以下 JSON 格式 ( http://www.codeshare.io/EvIdN ) 的情况下,我如何获得所有消息的列表<>。
提前致谢!
最佳答案
将所有消息选择为字符串(不检查错误):
var arr = ((JArray) obj["posts"]["data"]).Select(e => (string) ((JValue) e["message"]).Value).ToList();
关于c# - JSON.Net 为所有消息解析 Facebook Graph JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30411318/