Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Utf8Json库进行序列化时是否排除空字段?_C#_Json_Serialization_Utf8json - Fatal编程技术网

C# 使用Utf8Json库进行序列化时是否排除空字段?

C# 使用Utf8Json库进行序列化时是否排除空字段?,c#,json,serialization,utf8json,C#,Json,Serialization,Utf8json,使用Utf8Jsonlibrary将POCO序列化为JSON字符串时,有没有办法忽略空字段 我在下面的类中有一个ToString方法,我在外部使用它,所以我想看看在进行序列化时是否有任何方法排除空字段?基本上,我不希望序列化后json字符串中出现空字段。我在这里使用的是Uft8Json库 public class Process { public Process() { } [DataMember(Name = "lang_code")] publi

使用
Utf8Json
library将POCO序列化为JSON字符串时,有没有办法忽略空字段

我在下面的类中有一个
ToString
方法,我在外部使用它,所以我想看看在进行序列化时是否有任何方法排除空字段?基本上,我不希望序列化后json字符串中出现空字段。我在这里使用的是
Uft8Json

public class Process
{
    public Process() { }

    [DataMember(Name = "lang_code")]
    public string LCode { get; set; }

    [DataMember(Name = "data_currency")]
    public string Currency { get; set; }

    [DataMember(Name = "country_code")]
    public string CCode { get; set; }

    public override string ToString()
    {
        return Utf8Json.JsonSerializer.ToJsonString(this);
    }
}
我试着读文件,但找不到。使用
Utf8Json
库有什么方法可以做到这一点吗?

使用:

return Utf8Json.JsonSerializer.ToJsonString(this, 
    Utf8Json.Resolvers.StandardResolver.ExcludeNull);