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值自动过滤,布布扣,bubuko.com

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

上一篇:[转]JavaScript可否多线程? 深入理解JavaScript定时机制


下一篇:[Js]基础知识