Mru*_*rug 1 .net c# json json.net
这是我的JSON:
"Dt": {
"20171021": {
"abc": "-"
},
"20171022": {
"abc": "-"
},
"20171023": {
"abc": "-"
},
"20171024": {
"abc": "-"
},
"20171025": {
"abc": "-"
}
}
Run Code Online (Sandbox Code Playgroud)
Dt内的属性都是动态的.它们都是日期,但是以字符串格式.所以我在想如果我需要一个List对象,但是JSON.Net如何将它映射到List?我在想类结构类似于:
public class Dt
{
public List<RealDate> RealDates { get; set;}
}
public class RealDate
{
public string Date{ get; set;} //to hold "20171021"
public Tuple<string, string> Keys {get; set;} // to hold abc as Key1 and - as Key2
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
这看起来像没有Dt,而且,目前的事情有一个Dt实际上应该有:
public Dictionary<string, Foo> Dt { get; set;}
Run Code Online (Sandbox Code Playgroud)
在哪里Foo:
class Foo {
public string abc {get;set}
}
Run Code Online (Sandbox Code Playgroud)
然后,您将对此进行后处理,以将DTO模型(序列化模型)转换为实际模型.
请记住:任何时候序列化数据的外观和域模型之间的差异都很小:添加DTO模型,只需手动映射它们.它会拯救你的理智.