【发布时间】:2017-05-04 20:44:32
【问题描述】:
我目前正在获取一个形状类似于以下内容的 JSON 对象:
{
more data here...
"years": {
"value": 2013,
"item1": {
"total": 0.1044,
"Low": 0.0143,
"Mid": 0.1044,
"High": 0.3524,
"min": 0.0143,
"max": 0.3524,
},
"item2": {
"total": 0.1702,
"Low": 0.167,
"Mid": 0.1702,
"High": 0.1737,
"min": 0.167,
"max": 0.1737,
},...
}
}
不幸的是,我无法控制 JSON 的形状。
我正在尝试让 RestSharp 将其反序列化为一个对象,其中 Item1、Item2 和其余部分填充到一个字典中我目前有以下代码:
public class Year
{
public int Value { get; set; }
public Dictionary<string, Data> Data { get; set; }
}
public class Data
{
public decimal Total { get; set; }
public decimal Low { get; set; }
public decimal Mid { get; set; }
public decimal High { get; set; }
public decimal Min { get; set; }
public decimal Max { get; set; }
}
我希望Item1,Item2等成为Dictionary的键,下面的值填充Data类作为Dictionary的值。但目前它不起作用(我的结构的其余部分是,它只是最里面的部分)。我只是接近结构错误吗?我想避免为 Item1 和 Item2 创建一个特定的类。
【问题讨论】:
标签: c# restsharp json-deserialization