Json.NET将"不区分大小写的属性反序列化"列为广告功能之一.我已经读过,将首先尝试匹配指定属性的大小写,如果未找到匹配项,则执行不区分大小写的搜索.但是,这似乎不是默认行为.请参阅以下示例:
var result =
JsonConvert.DeserializeObject<KeyValuePair<int, string>>(
"{key: 123, value: \"test value\"}"
);
// result is equal to: default(KeyValuePair<int, string>)
Run Code Online (Sandbox Code Playgroud)
如果更改了JSON字符串以匹配属性的情况("Key"和"Value"vs"key"和"value"),那么一切都很好:
var result =
JsonConvert.DeserializeObject<KeyValuePair<int, string>>(
"{Key: 123, Value: \"test value\"}"
);
// result is equal to: new KeyValuePair<int, string>(123, "test value")
Run Code Online (Sandbox Code Playgroud)
有没有办法执行不区分大小写的反序列化?