How to omit empty collections when serializing with Json.NET

前端 未结 2 569
渐次进展
渐次进展 2021-01-08 00:36

I\'m using Newtonsoft\'s Json.NET 7.0.0.0 to serialize classes to JSON from C#:

class Foo
{
    public string X;
    public List Y = new List&l         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-08 00:40

    If you can modify your classes, you could add Shrink method and set null for all empty collections. It requires to change the class but it has better performance. Just another option for you.

提交回复
热议问题