How do deserialize this JSON into an object?

前端 未结 5 679
醉酒成梦
醉酒成梦 2021-01-14 02:36

I\'m trying to use JSON.Net to deserialize a JSON object into a C# object.

The object I want to create is MonthlyPerformance which contains a list of

5条回答
  •  天涯浪人
    2021-01-14 03:16

    Your property names do not match that of your JSON. I would expect the serialization to fail.

    Given the JSON you posted I would expect your c# classes to look like this. I'm not familiar with JSON.net but I would assume they have a property decorator that would allow you to specify the name of the JSON property the c# prop matches too.

    public class MonthlyPerformance
    {
        public List Type { get; set; }
    }
    
    public class Type
    {
        public int id { get; set; }
        public string countryId { get; set; }
        public string Name { get; set; }
    
        public List Category { get; set; }
    
        public Type()
        {
    
        }
    }
    
    public class Category
    {
        public int id { get; set; }
        public string countryId { get; set; }
        public string name { get; set; }
    
        public List ConfigurationFund{ get; set; }
    
        public Category()
        {
    
        }
    }
    
    public class Fund
    {
        public int id { get; set; }
        public string countryId { get; set; }
        public string name { get; set; }
    
        public Fund()
        {
    
        }
    }
    

提交回复
热议问题