简体   繁体   English

如何通过FB.API调用解析具有多个ID的JSON

[英]How to parse a JSON with multiple id's given by FB.API call

EDIT: I "solved" it by not parsing anything and "reading" it by hand like so: 编辑:我通过不解析任何内容来“解决”它,然后像这样用手“读取”它:

foreach (string key in result.ResultDictionary.Keys)
{
    foreach (string key2 in ((IDictionary)result.ResultDictionary[key]).Keys)
    {
        Debug.Log(key2 + " : " + ((IDictionary)result.ResultDictionary[key])[key2]);
    }
}

Original question below 下面的原始问题

I have this snippet: 我有这个片段:

string query = "?ids=";
for (int i = 0; i < users.Length; i++)
{
    query += users[i].idFacebook + ",";
}
query = query .Remove(query.Length - 1);
FB.API(query, HttpMethod.GET, responseCallback);

Now in the callback I want to parse the JSON I got, but I don't know how to do it, it looks something like this: 现在在回调中,我想解析我得到的JSON,但是我不知道该怎么做,它看起来像这样:

{
    "facebook-id-1":
    {
        "name":"some name",
        "id":"facebook-id-1"
    },
    "facebook-id-2":
    {
        "name":"some name",
        "id":"facebook-id-2"
    },
    "facebook-id-3":
    {
        "name":"some name",
        "id":"facebook-id-3"
    },
}

I tried to use a struct to parse it, but I know I need another struct to read the "upper" nodes, but their names are the id's so I can't create a general struct to work with them 我试图使用一个结构来解析它,但是我知道我需要另一个结构来读取“上”节点,但是它们的名称是id的,所以我无法创建一个通用的结构来使用它们

struct fbResults
{
    public fbName[] users;
}

struct fbName
{
    public string name;
    public string id;
}

This is how I parse the JSON inside the callback: 这就是我解析回调内的JSON的方式:

fbResults fbUsers = JsonUtility.FromJson<fbResults>(result.RawResult);

I appreciate any help 感谢您的帮助

EDIT: Added more tags. 编辑:添加了更多标签。

I "solved" it by not parsing anything and "reading" it by hand like so: 我通过不解析任何内容并通过手工“读取”它来“解决”它,如下所示:

foreach (string key in result.ResultDictionary.Keys)
{
    foreach (string key2 in ((IDictionary)result.ResultDictionary[key]).Keys)
    {
        Debug.Log(key2 + " : " + ((IDictionary)result.ResultDictionary[key])[key2]);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM