1 //升级前
2 services.AddMvc()
3 .AddJsonOptions(options =>
4 {
5 options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); //序列化时key为驼峰样式
6 options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
7 options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
8 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; //忽略循环引用
9 });
10 //升级后(需要引入Microsoft.AspNetCore.Mvc.NewtonsoftJson包)
11 services.AddControllersWithViews()
12 .AddNewtonsoftJson(options =>
13 {
14 options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); //序列化时key为驼峰样式
15 options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
16 options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
17 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; //忽略循环引用
18 });