JsonSerializerSettings和Asp.Net Core

尝试设置JsonOutputFormatter选项:

var jsonFormatter = (JsonOutputFormatter) options.OutputFormatters.FirstOrDefault(f => f is JsonOutputFormatter); if (jsonFormatter != null) { jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); } 

要么

 mvcBuilder.AddJsonOptions(jsonOptions => { jsonOptions.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }); 

但是一旦我添加这个,我得到:

MissingMethodException:找不到方法:’Newtonsoft.Json.JsonSerializerSettings Microsoft.AspNet.Mvc.Formatters.JsonOutputFormatter.get_SerializerSettings()’。

我正在使用标准的Microsoft.AspNet.Mvc.Formatters.Json (6.0.0-rc1-final)

编辑:通过安装Newtonsoft.Json 6.0.6 (降级所有其他引用)解决它

有人已经有了吗? 谢谢..

.Net Core 1.0 RTM带有开箱即用的CamelCase格式。 这是RC2的行为变化 。 但是,如果您需要修改它,请尝试以下代码段:

 services.AddMvc() .AddJsonOptions(opt => { var resolver = opt.SerializerSettings.ContractResolver; if (resolver != null) { var res = resolver as DefaultContractResolver; res.NamingStrategy = null; // <

我假设您使用的是ASP.Net Core,您应该使用“Microsoft.AspNetCore.Mvc”:

所以替换这个:

 "Microsoft.AspNet.Mvc": "6.0.0-rc1-final" 

这样:

 "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final"