从对象字典C#中获取价值
我正在使用LiveConnect sdk来获取一些用户信息。
在做了必要的事情之后,这就是我得到的结果:
{ "id": "123456789", "name": "ab", "first_name": "a", "last_name": "b", "link": "https://profile.live.com/", "work": [], "gender": null, "emails": { "preferred": "a@live.com", "account": "a@live.com", "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" }
我需要在"emails"
获取"account"
"emails"
。
首先,当我得到这个字符串时,我做了以下事情:
public Dictionary userData = new Dictionary(); userData = deserializeJsonObject(); private Dictionary deserializeJsonObject(string json) { var jss = new JavaScriptSerializer(); var d = jss.Deserialize<Dictionary>(json); return d; }
现在,为了获得帐户电子邮件,我打算做以下事情:
string email = userData["emails"]["account"];
但由于这是一个字符串,对象字典,我得到一个错误,因为userData [“emails”]是一个对象,所以这是不可能的。
我怎样才能获得数据?
你有没有试过演员?
例如:
(userData["emails"] as Dictionary
要么:
((Dictionary