JSON序列化自动过滤NULL值

来源:互联网 发布:如何查苹果手机mac地址 编辑:程序博客网 时间:2024/06/06 02:52

使用Newtonsoft.Json.dll 序列化为json时主动将NULL值过滤掉,具体做法:

var jSetting = new JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore};var json = JsonConvert.SerializeObject(response, Formatting.Indented, jSetting);


之前转换的JSON为:



{"header":{"responseCode":"200""responseDesc"":"执行成功""responseDescErrorMsg":"""responseDescTime":"2015-07-07T13:40:48.7162196+08:00"},"body":{"order":{"orderid":"S1507070001"},"product":null}}


参加代码后转换出来的为:



{"header":{"responseCode":"200""responseDesc":"执行成功""responseDescErrorMsg":"""responseDescTime":"2015-07-07T13:40:48.7162196+08:00"},"body":{"order":{"orderid":"S1507070001"}}}


0 0
原创粉丝点击