Proper JSON serialization in MVC 4

前端 未结 4 2130
不思量自难忘°
不思量自难忘° 2020-11-27 02:54

I\'d like to have JSON \'properly\' serialized (camelCase), and the ability to change date formats if necessary.

For Web API it is very easy - in the Global.asax I

4条回答
  •  悲哀的现实
    2020-11-27 03:43

    Note that below information is for Asp .Net core
    

    .Net team has recently announced that MVC now serializes JSON with camel case names by default.

    With couple of lines below you would be able to enable this functionality:

    services
    .AddMvc()
    .AddJsonOptions(options =>
    options.SerializerSettings.ContractResolver = new DefaultContractResolver());
    

    I wrote little blog on the same which is here.

提交回复
热议问题