【发布时间】:2017-09-23 16:05:30
【问题描述】:
我想像这样反序列化一些 JSON 字符串:
{"time":1506174868,"pairs":{
"AAA":{"books":8,"min":0.1,"max":1.0,"fee":0.01},
"AAX":{"books":8,"min":0.1,"max":1.0,"fee":0.01},
"AQA":{"books":8,"min":0.1,"max":1.0,"fee":0.01}
}}
其中 AAA、AAX、...有数百种变化
我将此 Json 作为类粘贴到 VS2017 中并得到以下内容:
public class Rootobject
{
public int time { get; set; }
public Pairs pairs { get; set; }
}
public class Pairs
{
public AAA AAA { get; set; }
public AAX AAX { get; set; }
public AQA AQA { get; set; }
}
public class AAA
{
public int books { get; set; }
public float min { get; set; }
public float max { get; set; }
public float fee { get; set; }
}
public class AAX
{
public int books { get; set; }
public float min { get; set; }
public float max { get; set; }
public float fee { get; set; }
}
public class AQA
{
public int books { get; set; }
public float min { get; set; }
public float max { get; set; }
public float fee { get; set; }
}
我会尽量避免数百个类声明,因为所有类都是相同的,除了 他们的名字。
我尝试将其序列化为数组或列表,但由于这不是数组而出现异常。
我使用 Newtonsoft JSON 库。
谢谢
【问题讨论】:
标签: c# json json-deserialization