Newtonsoft.Json 设置全局输出格式(日期格式,Json格式化,驼峰规则等)

 1 Newtonsoft.Json.JsonSerializerSettings setting = new Newtonsoft.Json.JsonSerializerSettings();
 2 JsonConvert.DefaultSettings = new Func<JsonSerializerSettings>(() =>
 3 {
 4 //日期类型默认格式化处理
 5 setting.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat;
 6 setting.DateFormatString = "yyyy-MM-dd HH:mm:ss";
 7 
 8 //空值处理
 9 //setting.NullValueHandling = NullValueHandling.Ignore;
10 
11 //驼峰
12 //setting.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
13 
14 //格式化Json
15 setting.Formatting = Formatting.Indented;
16 
17 return setting;
18 
19 
20 });
21 
22  

 

放在项目初始化的位置。

上一篇:.NET Core 3.0 Newtonsoft.Json反序化(Deserialize)TimeSpan报错问题


下一篇:【SSM项目整合】