.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 });
标签:core,key,DateTimeZoneHandling,NewtonsoftJson,3.0,SerializerSettings,序列化,options, 来源: https://www.cnblogs.com/zhang-wenbin/p/13139762.html