Json Null 不输出

[TestMethod]
       public void NodeTest()
       {
           datanode d = new datanode()
           {
               name = "zbw911",
               children = new List<datanode>
               {
                   new datanode
                   {
                       name = "1",
                       size = 99,
                   },
                   new datanode
                   {
                       name = "2",
                       size = 99,
                   }
               }
           };

           var x = Newtonsoft.Json.JsonConvert.SerializeObject(d,
               Newtonsoft.Json.Formatting.None,
               new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });

           Console.WriteLine(x);

       }
 

   class datanode
   {
       public string name { get; set; }

       public int? size { get; set; }

       public List<datanode> children { get; set; }

   }

 

 

适用于D3.js输出

 

 

测试名称:     NodeTest
测试结果:     已通过
结果 的标准输出:     {"name":"zbw911","children":[{"name":"1","size":99},{"name":"2","size":99}]}

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