Return camelCased JSON from Web API

前端 未结 6 1128
攒了一身酷
攒了一身酷 2020-12-31 11:42

I\'m trying to return camel cased JSON from an ASP.Net Web API 2 controller. I created a new web application with just the ASP.Net MVC and Web API bits in it. I hijacked t

6条回答
  •  余生分开走
    2020-12-31 12:04

    In your WebApiConfig.cs make sure to add those two lines

    // Serialize with camelCase formatter for JSON.
    var jsonFormatter = config.Formatters.OfType().First();
    jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
    

    make sure that you installed Newtonsoft library.

    Hope that helps.

提交回复
热议问题