asp.net core 默认输出的json数据首字母会改成小写,考虑可能是为了前端js的书写习惯,毕竟js 操作大小写敏感。
在Startup类的ConfigureServices()方法中进行配置,DefaultContractResolver() 原样输出,返回的 json 与后台定义一致
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
//options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();//json字符串大小写原样输出
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
//.AddJsonOptions(opt => {
// opt.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
// });// json字符串大小写原样输出
}