JSON.Net parse Facebook Graph JSON for all messages

南笙酒味 提交于 2019-12-11 05:55:04

问题


Using JSON.Net (http://www.newtonsoft.com/json/help/html/LINQtoJSON.htm) and the following code:

@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();




}

How would I get a List<> of all messages given the following JSON format (http://www.codeshare.io/EvIdN).

Thanks in advance!


回答1:


Selecting all messages as strings (no error checking):

var arr = ((JArray) obj["posts"]["data"]).Select(e => (string) ((JValue) e["message"]).Value).ToList();


来源:https://stackoverflow.com/questions/30411318/json-net-parse-facebook-graph-json-for-all-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!