1、安装库
install-package Microsoft.AspNetCore.Mvc.NewtonsoftJson
这个库很重要,默认是没有安装的。需要安装
2、配置
services.AddControllersWithViews()
.AddNewtonsoftJson(options=> {
options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); //序列化时key为驼峰样式 options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;//忽略循环引用 });
网友评论