赞
踩
在 Startup 类里的 ConfigureServices 方法里进行配置,只需一行代码
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.AddJsonOptions(opt => {
opt.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
});
}
DefaultContractResolver 是原样输出,后台属性怎么写的,返回的 json 就是怎样的。
CamelCasePropertyNamesContractResolver :驼峰命名法,首字母小写。如果变量全为大写,比如:NAME,返回的是 name
如果要全部小写的,可自行实现 DefaultContractResolver
public class LowercaseContractResolver : Newtonsoft.Json.Serialization.DefaultContractResolver
{
protected override string ResolvePropertyName(string propertyName)
{
return propertyName.ToLower();
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。