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
放在项目初始化的位置。