我正在使用 LiveConnect sdk 来获取一些用户信息。
在做了一切必要的事情之后,这就是我得到的结果:
{
"id": "123456789",
"name": "a b",
"first_name": "a",
"last_name": "b",
"link": "https://profile.live.com/",
"work": [],
"gender": null,
"emails": {
"preferred": "[email protected]",
"account": "[email protected]",
"personal": null,
"business": null
},
"addresses": {
"personal": {
"street": null,
"street_2": null,
"city": null,
"state": null,
"postal_code": null,
"region": null
},
"business": {
"street": null,
"street_2": null,
"city": null,
"state": null,
"postal_code": null,
"region": null
}
},
"locale": "en_US",
"updated_time": "2013-10-10T08:41:14+0000"
}
我需要得到"account"
inside "emails"
.
首先,当我得到这个字符串时,我做了以下操作:
public Dictionary<string, object> userData = new Dictionary<string, object>();
userData = deserializeJsonObject(<the string above>);
private Dictionary<string, object> deserializeJsonObject(string json)
{
var jss = new JavaScriptSerializer();
var d = jss.Deserialize<Dictionary<string, object>>(json);
return d;
}
现在,为了获取帐户电子邮件,我要做的事情如下:
string email = userData["emails"]["account"];
但由于这是一个字符串对象字典,我收到一个错误,指出这是不可能的,因为 userData["emails"] 是一个对象。
我如何获取数据?