.net core格式化响应数据(json驼峰格式)
作者:互联网
//表格字段都是大写的 想要实现首字母小写(特定操作配置输出序列化选项)
[HttpPost, ActionName("QueryAll")] public ActionResult QueryAll() { return new JsonResult( _bll.QueryAll(), new JsonSerializerOptions { DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,//key值驼峰显示 //PropertyNamingPolicy = JsonNamingPolicy.CamelCase value值驼峰显示 }); }
//Startup全局配置 var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers() .AddJsonOptions(options => { options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase; // options.JsonSerializerOptions.PropertyNamingPolicy= JsonNamingPolicy.CamelCase; });
标签:core,JsonNamingPolicy,驼峰,CamelCase,QueryAll,json,options,net,JsonSerializerOptio 来源: https://www.cnblogs.com/yyjspace/p/16422356.html