Program
C#
//安装Microsoft.AspNetCore.Mvc.NewtonsoftJson
// Add services to the container.
//设置Json返回的日期格式
builder.Services.AddControllers().AddNewtonsoftJson(options =>
{
//忽略循环引用
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
//统一设置API的日期格式
options.SerializerSettings.DateFormatString = "yyyy-MM-dd";
//设置Json返回格式同Model一致(Json里的首字母默认为小写,这里改为同后端Model一致)
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
验证
![](https://ichistudio.cn/wp-content/uploads/2023/09/图片-9-1024x331.png)