[英]JSON .NET - annot deserialize the current JSON object (e.g. {“name”:“value”}) into type 'System.Collections.Generic.List`1
I read a lot of topics about this problem but couldn't find a solution. 我阅读了很多有关此问题的主题,但找不到解决方案。 I have JSON returned by AP
我有AP返回的JSON
{
"Version": "XXX",
"StatusCode": 400,
"RequestId": "XXX",
"Success": false,
"ValidationMessages": {
"SomeTable[0].PropName": [
"This field is invalid"
],
"SomeTable[1].PropName": [
"This field is invalid"
],
"SomeTable[0].OtherProp": [
"This field is invalid"
]
},
"Result": {}
}
I created class: 我创建了课程:
public class MyResponse
{
public string Version { get; set; }
public string StatusCode { get; set; }
public string RequestId { get; set; }
public bool Success { get; set; }
public SomeResult Result { get; set; }
public List<KeyValuePair<string, List<string>>> ValidationMessages { get; set; }
}
When I am trying to deserialize JSON, I am getting an error from the title. 尝试反序列化JSON时,标题出现错误。 How can I achieve serialization of dynamic ValidationMessages?
如何实现动态ValidationMessages的序列化?
For your specific scenario you can use a Dictionary instead a List since dictionary implements an object and receives a key value pair, you can have a dynamic property name and whatever value you need (List of strings) 对于您的特定情况,您可以使用Dictionary而不是List,因为Dictionary实现了一个对象并接收一个键值对,您可以拥有一个动态属性名称以及所需的任何值(字符串列表)
public class MyResponse
{
public string Version { get; set; }
public string StatusCode { get; set; }
public string RequestId { get; set; }
public bool Success { get; set; }
public SomeResult Result { get; set; }
public Dictionary<string, List<string>> ValidationMessages {get;set;}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.