0

如何反序列化此文本。我尝试使用 JSON,但出现“无效 JSON 原语”错误。

{
"meta": {
  "limit": 20,
  "next": null,
  "offset": 0,
  "previous": null,
  "total_count": 1
},
"objects": [
  {
     "blocked": false,
     "groups": [],
     "id": "1111",
     "name": "John Doe",
     "number": "+15555555555",
     "resource_uri": "/api/v1/contacts/1111/"
  }
 ]
}

这是我使用的代码:

var jss = new JavaScriptSerializer();
var dictionary = jss.Deserialize<Dictionary<string, string>>(buffer.ToString());
4

1 回答 1

1

易于修复。反序列<Dictionary<string, object>化为<Dictionary<string, string>

var dictionary = jss.Deserialize<Dictionary<string, object>>(buffer.ToString());

完整的测试代码

string json = @"{
    ""meta"": {
        ""limit"": 20,
        ""next"": null,
        ""offset"": 0,
        ""previous"": null,
        ""total_count"": 1
    },
    ""objects"": [
        {
            ""blocked"": false,
            ""groups"": [],
            ""id"": ""1111"",
            ""name"": ""John Doe"",
            ""number"": ""+15555555555"",
            ""resource_uri"": ""/api/v1/contacts/1111/""
        }
        ]
    }";

var jss = new JavaScriptSerializer();
var dictionary = jss.Deserialize<Dictionary<string, object>>(json);
于 2012-12-10T18:27:08.100 回答