我正在检索以下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
的结果就像嵌套字典一样,我找不到直接检索国家/地区名称的方法。
答案 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;
}