Json 用 in a List 反序列化列表
是否可以使用 JsonConvert.DeserializeObject 反序列化列表中的列表?
Object:
public class BusinessList
{
public long Number{ get; set; }
public string BusinessUnitCode { get; set; }
public List<string> Codes { get; set; }
}
Json:
{"Number":111121,"BusinessUnitCode":"ABC","Codes":["11111-2","14333-8"]}
Deserialization:
var dataList = (List<BusinessList>)JsonConvert.DeserializeObject(reciveObject, typeof(List<BusinessList>), jsonSerializerSettings);
错误:
"Expected a JsonObjectContract or JsonDictionaryContract for
type 'System.Collections.Generic.List`1
[PathResultsPortal.UI.Controllers.AnalyteDetails]',
got 'Newtonsoft.Json.Serialization.JsonArrayContract'."
如果您从 BusinessList 对象中删除代码列表,它工作正常,但似乎无法处理列表中的列表,这是否可能?
Is it possible to deserialise a list with in a list using the JsonConvert.DeserializeObject?
Object:
public class BusinessList
{
public long Number{ get; set; }
public string BusinessUnitCode { get; set; }
public List<string> Codes { get; set; }
}
Json:
{"Number":111121,"BusinessUnitCode":"ABC","Codes":["11111-2","14333-8"]}
Deserialization:
var dataList = (List<BusinessList>)JsonConvert.DeserializeObject(reciveObject, typeof(List<BusinessList>), jsonSerializerSettings);
Error:
"Expected a JsonObjectContract or JsonDictionaryContract for
type 'System.Collections.Generic.List`1
[PathResultsPortal.UI.Controllers.AnalyteDetails]',
got 'Newtonsoft.Json.Serialization.JsonArrayContract'."
If you remove the Codes List from the BusinessList Object it works fine it can't seem to handle the list with in a list, is it even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
try this