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}]}