【发布时间】:2018-12-11 07:02:47
【问题描述】:
我正在尝试将 JSON 数据从 API 转换为列表。这是我从 API 中得到的:
{
"0":{
"Id":0,
"FNr":"1",
"Len":"1",
"Typ":"1",
"Sort":"1",
"Low":"1",
"Up":"1",
"Rep":"1",
"UC":"1",
"Lo":"1",
"Pf":"1",
"SelP":"1",
"Rel":"1",
"RefLen":"1",
"Description":"1",
"Remarks":"1"
},
"1":{
...
},
"2":{
...
}
}
现在我尝试将其反序列化为List<DBTableEntryModel>
var entries = JSON.Deserialize<List<DbTableEntryModel>>(jsonString);
这失败了,因为数字。如果我删除 JSON 字符串的数字,它工作得很好。有没有更简单的方法来解决这个问题,而无需拆分 JSON 字符串?
这是我的 DBTableEntryModel:
public class DbTableEntryModel
{
[StringLength(3)]
[ColumnWidth("30px")]
public string FNr { get; set; }
[StringLength(5)]
[ColumnWidth("60px")]
public string Len { get; set; }
[StringLength(3)]
[ColumnWidth("30px")]
public string Typ { get; set; }
[StringLength(3)]
[ColumnWidth("35px")]
public string Sort { get; set; }
[StringLength(10)]
[ColumnWidth("100px")]
public string Low { get; set; }
[StringLength(10)]
[ColumnWidth("100px")]
public string Up { get; set; }
[StringLength(1)]
[ColumnWidth("30px")]
public string Rep { get; set; }
[StringLength(1)]
[ColumnWidth("25px")]
public string UC { get; set; }
[StringLength(1)]
[ColumnWidth("25px")]
public string Lo { get; set; }
[StringLength(1)]
[ColumnWidth("25px")]
public string Pf { get; set; }
[StringLength(2)]
[ColumnWidth("34px")]
public string SelP { get; set; }
[ColumnWidth("90px")]
public string Rel { get; set; }
[ColumnWidth("90px")]
public string RefLen { get; set; }
[TextArea]
[Display(Name = "Description", ResourceType = typeof(Resources.Plugin))]
public string Description { get; set; }
[TextArea]
[Display(Name = "Remarks", ResourceType = typeof(Resources.Plugin))]
public string Remarks { get; set; }
}
【问题讨论】:
-
能否请您出示您的
DbTableEntryModel?
标签: c# json list serialization