Newtonsoft.Json.dll序列化为json,null值自动过滤

原文:Newtonsoft.Json.dll序列化为json,null值自动过滤

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

之前转换的JSON为:

{"header":{"rspCode":"0000","rspDesc":"执行成功","rspErrorMsg":"","rspTime":"2014-03-05T13:40:48.7162196+08:00"},"body":{"order":{"orderid":"S0000001"},"product":null}}

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

{"header":{"rspCode":"0000","rspDesc":"执行成功","rspErrorMsg":"","rspTime":"2014-03-05T13:40:48.7162196+08:00"},"body":{"order":{"orderid":"S0000001"}}}

Newtonsoft.Json.dll序列化为json,null值自动过滤,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。