-1
我正在开发一个非常简单的.net 4.6中的WebAPI。 WebAPI,默认情况下使用JSON.Net作为JSON序列化程序。 对于这个应用程序,我愿意将默认的JSON序列化程序设置为NewtonSoft JSON。C#WebAPI:将默认的JSON序列化程序设置为NewtonSoft JSON
请帮我我如何做到这一点。
我正在开发一个非常简单的.net 4.6中的WebAPI。 WebAPI,默认情况下使用JSON.Net作为JSON序列化程序。 对于这个应用程序,我愿意将默认的JSON序列化程序设置为NewtonSoft JSON。C#WebAPI:将默认的JSON序列化程序设置为NewtonSoft JSON
请帮我我如何做到这一点。
var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
formatter.SerializerSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
TypeNameHandling = TypeNameHandling.Objects,
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
将被放置在您的global.asax
是的,这是为我工作。 JSON.Net在反序列化过程中失败,我从客户端发送使用Newtonsoft序列化的数据。 –
JSON.Net是NewtonSoft的JSON序列。 http://www.newtonsoft.com/json/help/html/Introduction.htm –
同意。谢谢@MurrayFoxcroft –