ASP.NET WebAPI JSON Binding Case-Sensitivity

后端 未结 2 1447
甜味超标
甜味超标 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: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();
    

提交回复
热议问题