-2

我有一个字符串中的 JSON。如何使用 JavascriptSerializer 对其进行反序列化并找到 SSOID 的值?

{
"Addresses":  [
    {
        "Address": "123 Test Road",
        "State": "Mississippi"
    }
],
"Birthdate": "April 12 2012",
"CreateDate": "April 13 2012",
"IDs": [
    {
        "isDefault": false,
        "PurchaseID": "883"
    }
],
"Sex": "Male",
"SSOID": 23444,
"Suffix": null,
"BoardID": 4324
}
4

3 回答 3

1

在这种特殊情况下:

string s = "your json string";   
System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
var obj = js.DeserializeObject(s) as Dictionary<string,object>;
int ssoid = (int)obj["SSOID"];
于 2012-04-13T20:42:55.797 回答
1
var js = new JavaScriptSerializer();
var deserialized = (Dictionary<string, object>) js.DeserializeObject(json);
var ssoid = (int) deserialized["SSOID"];
于 2012-04-13T20:44:14.487 回答
0
 var SSOID = new JavaScriptSerializer()
                    .Deserialize<Dictionary<string, object>>(json)["SSOID"];

或者

dynamic jObj = new JavaScriptSerializer().DeserializeObject(json);
var SSOID = jObj["SSOID"];
于 2012-04-13T20:45:10.553 回答