我有包含重复成员的 JSON:
[
{
"MyProperty": "MyProperty1",
"MyProperty": "MyWrongProperty1",
"MyProperty2": "MyProperty12",
"MyProperty2": "MyWrongProperty2"
},
{
"MyProperty": "MyProperty21",
"MyProperty2": "MyProperty22"
}
]
当我反序列化时,它正在获取最后一个属性。这是代码:
var myJson = File.ReadAllText("1.txt");
List<MyClass> myClasses = JsonConvert.DeserializeObject<List<MyClass>>(myJson);
但是当 JSON 字符串包含重复的属性时,我需要抛出异常。我怎样才能做到这一点?