- Newtonsoft.Json.JsonSerializerSettings setting = new Newtonsoft.Json.JsonSerializerSettings();
- JsonConvert.DefaultSettings = new Func<JsonSerializerSettings>(() =>
- {
- //日期类型默认格式化处理
- setting.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat;
- setting.DateFormatString = "yyyy-MM-dd HH:mm:ss";
- //空值处理
- setting.NullValueHandling = NullValueHandling.Ignore;
- //高级用法九中的Bool类型转换 设置
- setting.Converters.Add(new BoolConvert("是,否"));
- return setting;
- });
序列化时 指定Key的处理方式,为驼峰式
CamelCasePropertyNamesContractResolver
//设置序列化时key为驼峰样式
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
settings.Formatting = Formatting.Indented;
string str = JsonConvert.SerializeObject(menus, settings);
原文地址:https://www.cnblogs.com/94cool/p/9650616.html
时间: 2024-11-07 16:08:48