zoukankan      html  css  js  c++  java
  • 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}]}

  • 相关阅读:
    Python 2 与 python 3的区别
    语法基础题
    Python运算符_ 2018-07-26
    Python 各种语句:2018-07-27
    解决在Python中使用Win32api报错的问题,No module named win32api
    在CenOS7.5里安装Redis
    下载Redis
    重置CentOS6.5的登录口令
    如何在CentOS里切换操作系统所用的语言,中英文切换
    在Ubuntu里安装Mysql5.7.23
  • 原文地址:https://www.cnblogs.com/zbw911/p/4233128.html
Copyright © 2011-2022 走看看