Unity Facebook SDK,登录后无法从词典中检索国家

时间:2018-11-24 23:12:33

标签: c# unity3d facebook-unity-sdk

我正在检索以下Facebook用户的国家/地区:

 void Get()
    {
        FB.API("/me?fields=location{location{country}}", HttpMethod.GET,this.callback1);
    }

    private void callback1(IResult result)
    {
        if (result.Error != null)
        {
            Debug.Log("FB.API result = null");
        }
        else
        {
            Dictionary<string, object> dict = Facebook.MiniJSON.Json.Deserialize(result.RawResult) as Dictionary<string, object>;
    }
}

这很好。

JSON如下:

{
  "location": {
    "location": {
      "country": "England"
    },
    "id": "111122233344"
  },
  "id": "1112299000"
}

问题是dict的结果就像嵌套字典一样,我找不到直接检索国家/地区名称的方法。

1 个答案:

答案 0 :(得分:0)

docs绘制,我无法测试这种端到端的外观:

var dict = Json.Deserialize(jsonString) as Dictionary<string,object>;

object locationH;
string country;
if(dict.TryGetValue ("location", out locationH)) {
  var location = (((Dictionary<string, object>)locationH) ["location"]);
  var countryDict = (((Dictionary<string, object>)location) ["country"]);
  country = (string)countryDict;
}