JSON.Net解析所有消息的Facebook图JSON [英] JSON.Net parse Facebook Graph JSON for all messages

查看:68
本文介绍了JSON.Net解析所有消息的Facebook图JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JSON.Net( http://www.newtonsoft.com/json /help/html/LINQtoJSON.htm )和以下代码:

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




}

如何使用以下JSON格式( http://www.codeshare .io/EvIdN ).

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

提前谢谢!

推荐答案

选择所有消息作为字符串(无错误检查):

Selecting all messages as strings (no error checking):

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

这篇关于JSON.Net解析所有消息的Facebook图JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆