C# WebAPI: Set default JSON serializer to NewtonSo

2019-07-26 08:43发布

I am developing a very simply WebAPI in .Net 4.6. WebAPI, by default use JSON.Net as JSON serializer. For this application, I am willing to set default JSON serializer to NewtonSoft JSON.

Please help me how I can do this.

1条回答
家丑人穷心不美
2楼-- · 2019-07-26 09:24
var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
    formatter.SerializerSettings = new JsonSerializerSettings
    {
        Formatting = Formatting.Indented,
        TypeNameHandling = TypeNameHandling.Objects,
        ContractResolver = new CamelCasePropertyNamesContractResolver()
    };

Would be placed in your global.asax

查看更多
登录 后发表回答