是否可以指定一些反序列化选项来使用Json.NET执行区分大小写的反序列化?
建议:
public class Account { public string Email { get; set; } public bool Active { get; set; } public DateTime CreatedDate { get; set; } public IListRoles { get; set; } }
从反序列化时必须失败:
{ "email": "james@example.com", "active": true, "createdDate": "2013-01-20T00:00:00Z", "roles": [ "User", "Admin" ] }
Jeff Mercado.. 16
不幸的是不太可能.它似乎是硬编码,尝试区分大小写,然后不区分大小写.
////// Gets the closest matching /// Name of the property. ///object. /// First attempts to get an exact case match of propertyName and then /// a case insensitive match. /// A matching property if found. public JsonProperty GetClosestMatchProperty(string propertyName) { JsonProperty property = GetProperty(propertyName, StringComparison.Ordinal); if (property == null) { property = GetProperty(propertyName, StringComparison.OrdinalIgnoreCase); } return property; }
JsonPropertyCollection
这是由内部阅读器调用的,因此没有简单的开关可以翻转.它应该是可能的,但您必须自己编写转换器以拒绝不区分大小写的匹配.
不幸的是不太可能.它似乎是硬编码,尝试区分大小写,然后不区分大小写.
////// Gets the closest matching /// Name of the property. ///object. /// First attempts to get an exact case match of propertyName and then /// a case insensitive match. /// A matching property if found. public JsonProperty GetClosestMatchProperty(string propertyName) { JsonProperty property = GetProperty(propertyName, StringComparison.Ordinal); if (property == null) { property = GetProperty(propertyName, StringComparison.OrdinalIgnoreCase); } return property; }
JsonPropertyCollection
这是由内部阅读器调用的,因此没有简单的开关可以翻转.它应该是可能的,但您必须自己编写转换器以拒绝不区分大小写的匹配.