C#WebAPI:将默认的JSON序列化程序设置为NewtonSoft JSON

Ran*_*mar 3 c# asp.net-mvc asp.net-web-api

我正在.Net 4.6中开发一个非常简单的WebAPI.WebAPI默认使用JSON.Net作为JSON序列化程序.对于此应用程序,我愿意将默认的JSON序列化程序设置为NewtonSoft JSON.

请帮助我如何做到这一点.

DSh*_*rty 13

var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
    formatter.SerializerSettings = new JsonSerializerSettings
    {
        Formatting = Formatting.Indented,
        TypeNameHandling = TypeNameHandling.Objects,
        ContractResolver = new CamelCasePropertyNamesContractResolver()
    };
Run Code Online (Sandbox Code Playgroud)

将放在你的 global.asax