当使用JSON时.Net在ASP.Net Core 2.2在序列化为JSON时,当属性值为null时,我可以忽略该属性:

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public DateTime? Created { get; set; }

But when using the new ASP.Net Core 3.0 built in JSON (System.Text.Json) I can’t find an equivalent attribute to ignore a property if its value is null.

I could only find JsonIgnore.

我错过什么了吗?

推荐答案

This was fixed on .Net 5

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]

请参阅下面的更新

https://github.com/dotnet/runtime/issues/41313

https://github.com/dotnet/runtime/issues/30687

Json相关问答推荐

如何在VegaLite中应用Times New Roman,CaliBiri字体

Jolt需要将缺少的值设置为空并保持相同的位置

解析JSON说函数parse_json不存在?

使用JQ将JSON输出转换为CSV复杂 struct

在linux控制台中解析json字符串的最简单方法是什么?

jq 对特定键进行过滤并将值整理到单个 csv 单元格中

Powershell解析JSON文件中的键或值

如何在JQ中展平多维数组

根据数据框中的其他列值将列表 json 对象插入行

在循环中将变量添加到 bash 数组

序列化特定类型时如何使 JSON.Net 序列化程序调用 ToString()?

如何从 HttpClient 解析 JSON 字符串?

如何为名称/值 struct 创建 JSON 模式?

Jackson 中的 readValue 和 readTree:何时使用哪个?

JSON对象中的JavaScript递归搜索

读取 HttpwebResponse json 响应,C#

使用 jq 如何用其他名称替换键的名称

Java循环遍历Json数组?

我可以使用空字符串作为对象标识符吗?

Python 到 JSON 序列化在十进制上失败