Facebook.MiniJSON 反序列化下面的注释和嵌套值 from returning no values

Facebook.MiniJSON Deserialize comments and nested values under from returning no values

我们正在使用 FB.API 调用来检索 post 上的评论,我们无法检索嵌套在 "from" 下的数据。

API 资源管理器命令:“10153539873517828/评论?”

C#代码

 FB.API("/10153539873517828/comments?", HttpMethod.GET, delegate (IGraphResult result)
                {
             string jsonMessage = result.RawResult;
             Debug.Log(jsonMessage);
             var soap = Json.Deserialize(jsonMessage) as Dictionary<string,object>;
             List<object> entries = soap["data"] as List<object>;

             try
             {
                 for (int i = 0; i < soap.Count; i++)
                 {
                     Dictionary<string,object> messageData = entries[i] as Dictionary<string,object>;
                     object resultData = messageData["message"];             (Works)
                     object resultData = messageData["name"];                  (Blank)
                     Debug.Log("JSON string : " + resultData.ToString());
                 }
             }
             catch
             {
                 Debug.Log("Done!!!");
             }
         });

JSON 字符串

{
   "data": [
     {
       "created_time": "2016-03-31T11:10:18+0000",
       "from": {
         "name": "Hello world",
         "id": "298062736962722"
       },
       "message": "Test comment",
       "id": "10153539873517828_10153539875377828"
     },
     {
       "created_time": "2016-03-31T11:12:47+0000",
       "from": {
         "name": "Hello world",
         "id": "298062736962722"
       },
       "message": "people must be wonder what the bleep is this, lol.",
       "id": "10153539873517828_10153539877202828"
     }
   ],
   "paging": {
     "cursors": {
       "before": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEF4TlRNMU16azROelV6TnpjNE1qZAzZANVFExT1RReU1qWXhPQT09",
       "after": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEF4TlRNMU16azROemN5TURJNE1qZAzZANVFExT1RReU1qYzJOdz09"
     }
   }
 }

在尝试获取"name"和关联的"id"时,我们可以成功获取"data"下的"message"和"id" returns 空白值。

我们已经阅读了很多 post 并查看了人们 post 提供的一些解决方案,但我们没有找到任何有助于解决问题的方法。

由于我们使用的是 FB SDK,因此我们应该能够使用 Facebook.MiniJSON 来反序列化上述字符串。正在检索:

      {
    "created_time": "2016-03-31T11:10:18+0000",
    "from": {
      "name": "Hello world",
      "id": "298062736962722"
    },
    "message": "Test comment",
    "id": "10153539873517828_10153539875377828"
  },

开发者文档中的所有示例都只涉及一级检索,我们该如何解决?

name 在您搜索的上下文中不存在。唯一可用的键是 created_timefrommessageid。您必须从 from 创建一个字典并从中引用 name。这是我建议的更改。这没有经过测试,我只是抓住了你的内部 for 循环并对其进行了修改。显然集成回您的代码的其余部分。

...
for (int i = 0; i < soap.Count; i++)
{
    Dictionary<string,object> messageData = entries[i] as Dictionary<string,object>;
    object resultData = messageData["message"];
    Dictionary<string,object> fromData = messageData["from"] as Dictionary<string, object>;
    object resultData = fromData["name"]
    Debug.Log("JSON string : " + resultData.ToString());
}
...