.net core 2.0 3.0 NewtonsoftJson配置

复制代码

 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     });
posted @ 2020-06-16 10:50  恋之呓  阅读(562)  评论(0编辑  收藏  举报