- 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);