【发布时间】:2016-09-05 21:50:41
【问题描述】:
我有这个 json:
"rates": {
"AT": {
"country": "Austria",
"standard_rate": 20.00,
"reduced_rate": 10.00,
"reduced_rate_alt": 13.00,
"super_reduced_rate": false,
"parking_rate": 12.00
},
"BE": {
...
我尝试用这个类映射这个 json,但我遇到了一个问题,因为 json 的排列方式是一个标签是一个对象。我需要成为一个属性
public class Rate{
public string Tag { get; set; }
public string country { get; set; }
public double standard_rate { get; set; }
public double reduced_rate { get; set; }
public double reduced_rate_alt { get; set; }
public bool super_reduced_rate { get; set; }
public double parking_rate { get; set; }
}
我如何将它映射到一个单一的对象?提前致谢
【问题讨论】:
-
JSON 中的
Tag在哪里? -
我想要的标签等于'AT'或'BE'
-
AT 和 BE 的行为更像是字典中的键 - 查看结构:这些与其余数据无关。如果你必须让它成为一个属性,你需要编写你自己的转换器,我想。
-
是 AT 和 BE 是字典的标识。我如何转换?我无法更改输出,因为是外部 Web 服务。