JsonSerializerSettings settings = new JsonSerializerSettings(); //EF Core中默认为驼峰样式序列化处理key //settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); //使用默认方式,不更改元数据的key的大小写 settings.ContractResolver = new DefaultContractResolver(); return Json(data, settings);
全局设置,Json序列化配置
public void ConfigureServices(IServiceCollection services){ // Add framework services. services.AddMvc() //全局配置Json序列化处理 .AddJsonOptions(options => { //忽略循环引用 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; //不更改元数据的key的大小写 options.SerializerSettings.ContractResolver = new DefaultContractResolver(); } );}