码迷,mamicode.com
首页 > Web开发 > 详细

JSON序列化自动过滤NULL值

时间:2015-07-07 14:46:44      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:

使用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"}}}


版权声明:本文为博主原创文章,未经博主允许不得转载。

JSON序列化自动过滤NULL值

标签:

原文地址:http://blog.csdn.net/y0ungroc/article/details/46788585

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!