在C#中解析Facebook Open Graph API JSON响应 [英] Parsing Facebook Open Graph API JSON Response in C#

查看:119
本文介绍了在C#中解析Facebook Open Graph API JSON响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试解析以下链接的JSON响应:
https://graph.facebook.com/feed/?ids=135395949809348,149531474996&access_token=

I try to get parse JSON response for the following link: https://graph.facebook.com/feed/?ids=135395949809348,149531474996&access_token=

响应如下:

{
   "135395949809348": {
      "data": [
         {
             ....Some data
         }]
     }
,
   "325475509465": {
      "data": [
         {
       ....Some data......
      }]
    }
}

我使用System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(string json)方法。
但对象的键名总是不同的,所以我无法定义可用于解析此响应的类。
任何人都有从解析多个id的响应的经验?

I use System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(string json) method. But the objects key names always different , so I can't define the class that can be used for parsing this response. Is anyone has any experience in parsing multiple id's response from Facebook?

推荐答案

使用JSON.NET,您可以读取作为JObject的respose,然后通过索引器访问。

With JSON.NET you can read the respose as JObject and then access it via indexer.

var json = JObject.Parse(result);
var array = json["325475509465"]["data"];

然后你可以反序列化数组中的对象...

Then you can deserialize objects from array...

这篇关于在C#中解析Facebook Open Graph API JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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