简体   繁体   中英

JSON deserialization class

Cant figure out where i deserialized wrong?

C# JSON classes:

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; }
}

My JSON string:

[{
"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": ...

And deserialization code:

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

The problem is on your deserialization line. You can simply do this :

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

Hope it helps !

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM