JSON反序列化类



无法找出我反序列化的错误位置?

C#JSON类:

AllProjects [] AllProjectsList;
public class AllProjects
{
    public Project [] Projects { get; set; }
}
public class Project
{
    [JsonProperty("self")]
    public string self { get; set; }
    [JsonProperty("id")]
    public string id { get; set; }
    [JsonProperty("key")]
    public string key { get; set; }
    [JsonProperty("name")]
    public string name { get; set; }
    [JsonProperty("avatarUrls")]
    public Dictionary<string, string> Result { get; set; }
}

我的JSON字符串:

[{
"self":"https://test.test.com/rest/api/2/project/AAAVOA",
"id":"11211",   
"key":"AAAVOA",
"name":"AAA VOA",
"avatarUrls":   
    {
        "16x16":"https://test.test.com/secure/projectavatar?size=small&pid=11211&avatarId=10281",
        "48x48":"https://test.test.com/secure/projectavatar?pid=11211&avatarId=10281"
    }
},
{
"self": ...

和反序列化代码:

 AllProjectsList = JsonConvert.DeserializeObject<AllProjects>(response.Content) as AllProjects;

问题出在反序列化行上。你可以简单地这样做:

List<Project> projects = JsonConvert.DeserializeObject<List<Project>>(response.Content);

希望它能有所帮助!

您可以查看json2csharp来了解类的外观。

相关内容

  • 没有找到相关文章

最新更新