可以自己写一个转换器
·
services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = new UpperFirstCaseNamingPolicy();
});
转换器代码:
/// <summary>
/// 首字母大写
/// </summary>
public class UpperFirstCaseNamingPolicy:JsonNamingPolicy
{
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public override string ConvertName(string name) =>
name.UpperFirst();
}
另外如果有这段代码要去掉:
services.AddControllers().AddNewtonsoftJson();
微软官网文档:
JsonSerializerOptions.PropertyNamingPolicy 属性 (System.Text.Json) | Microsoft Learn