Unity Facebook SDK,登录后无法从字典中检索国家
Unity Facebook SDK, can't retrieve Country from Dictionary after Login
我正在按以下方式检索 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
结果就像嵌套字典,我找不到直接检索国家/地区名称的方法。
我无法测试这个端到端,从 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;
}
我正在按以下方式检索 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
结果就像嵌套字典,我找不到直接检索国家/地区名称的方法。
我无法测试这个端到端,从 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;
}