1

我正在使用Json.NET转换 JSON 字符串,我只是在这里粘贴一个小字符串:

"incentive_type":{"cost":0,"id":4}

"incentive_type":{"cost":{"points":400,"denom":null,"acc":{"foil":{},"rates":{}}},"id":4}

我已经声明incentive_type为:

public class incentive_type
{
    public cost cost { get; set; }
    public int id { get; set; }
}

public class cost
{
    public cost()
    {
    }
    public Dictionary<string,int> points { get; set; }
    public Dictionary<string,string> denom { get; set; }
    public acc acc { get; set; }
}

public class acc
{
    public Dictionary<string,int> foil{ get; set; }
    public Dictionary<string,int> rates { get; set; }
}

在反序列化时我得到

无法将 0 转换为类型“成本”

原因是第一个 JSON 字符串的类为 0。如何设置我的班级来处理这个值?

4

0 回答 0