ASP.NET WebAPI JSON Binding Case-Sensitivity

后端 未结 2 1446
甜味超标
甜味超标 2021-02-07 04:53

Upgrading from ASP.NET WebAPI Beta to RC has provided some amount of excitement and a great deal of frustration. I have been able to work through the majority of the issues, bu

相关标签:
2条回答
  • 2021-02-07 05:03

    After digging into this issue in significant depth I came to realize that I was hitting a bug in the Json.NET KeyValuePair converter. James Newton-King was kind enough to answer my related question and provided a link to the fix:

    Json.NET Case-insensitive Property Deserialization

    0 讨论(0)
  • 2021-02-07 05:16

    The Json.NET formatter is case insensitive for deserialization (json -> CLR).

    On serialization, you can get camel casing by using the CamelCasePropertyNamesContractResolver.

    In your Global.asax:

    var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
    json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
    
    0 讨论(0)
提交回复
热议问题