我读了很多有关此问题的主题,但找不到解决方案。我让JSON返回AP
{
"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": {}
}
我创建了类:
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; }
}
当我试图估算JSON时,我会从标题中获得错误。如何实现动态验证的序列化?
对于您的特定方案,您可以使用字典代替列表,因为字典实现对象并接收键值对,您可以具有动态属性名称和任何需要的值(列表(字符串(
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;}
}