.net core格式化响应数据(json驼峰格式)

//表格字段都是大写的 想要实现首字母小写(特定操作配置输出序列化选项)
[HttpPost, ActionName("QueryAll")] public ActionResult QueryAll() { return new JsonResult( _bll.QueryAll(), new JsonSerializerOptions { DictionaryKeyPolicy = JsonNamingPolicy.CamelCase,//key值驼峰显示 //PropertyNamingPolicy = JsonNamingPolicy.CamelCase value值驼峰显示
          //如果想维持原状 设置
DictionaryKeyPolicy、PropertyNamingPolicy 为null即可

}); }
//Startup全局配置

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers()
    .AddJsonOptions(options =>
    {
        options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
// options.JsonSerializerOptions.PropertyNamingPolicy= JsonNamingPolicy.CamelCase;

    });

 

posted @ 2022-06-29 10:30  艺洁  阅读(579)  评论(0编辑  收藏  举报