首页 > Web开发 > 详细

JSON序列化自己主动过滤NULL值

时间:2017-07-15 10:56:58      阅读:227      评论: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://www.cnblogs.com/zhchoutai/p/7181412.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!