Json.NET case-sensitive deserialization

后端 未结 1 2004
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-07 02:03

Is it possible to specify some deserialization options to perform case-sensitive deserialization with Json.NET?

Suggest:

public class Account
{
    p         


        
1条回答
  •  甜味超标
    2020-12-07 02:20

    Not likely unfortunately. It seems to be hardcoded to try case-sensitive then case-insensitive.

    /// 
    /// Gets the closest matching  object.
    /// First attempts to get an exact case match of propertyName and then
    /// a case insensitive match.
    /// 
    /// Name of the property.
    /// 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

    This is invoked by the internal reader so there's no simple switch that you could just flip. It should be possible, but you would have to write the converter yourself to reject case-insensitive matches.

    0 讨论(0)
提交回复
热议问题