c# - .NET core 3 : Order of serialization for JsonPropertyName (System. 文本.Json.序列化)

标签 c# json migration .net-core-3.0 system.text.json

在迁移到 .NET Core 3 时,我已从 Newtonsoft.Json 序列化切换到 System.Text.Json.Serialization。在所有功能中,我想继续使用 JsonPropertyName 属性。

允许的 Newtonsoft 版本 ordering of serialized attributes :

[JsonProperty(Order = 1)]
public bool Deleted { get; set; }

[JsonProperty(Order = 2)]
public DateTime DeletedDate { get; set; }

有没有办法在 System.Text.Json.Serialization 中实现相同的目的?

最佳答案

它在 .Net 6 及更高版本中受支持,使用 JsonPropertyOrderAttribute :

JsonPropertyOrderAttribute Class

Specifies the property order that is present in the JSON when serializing. Lower values are serialized first. If the attribute is not specified, the default value is 0.

If multiple properties have the same value, the ordering is undefined between them.

该属性可以是 applied例如如下:

[JsonPropertyOrder(order : 1)]

关于c# - .NET core 3 : Order of serialization for JsonPropertyName (System. 文本.Json.序列化),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59134564/

相关文章:

c# - 可移植类库 : navigate to xaml page

C# HttpClient 或 HttpWebRequest 类

java - 使用 editcell 启用卡住 jqgrid

django - contenttypes.contenttype 在此迁移中不可用

c# - MS 出版商自动化

c# - EWS 中 ItemView 的最大尺寸是多少?

javascript - 将 JS 对象提取为 JSON

python - 如何在 python-jsonschema 文档中设置本地文件引用?

php - CakePHP 迁移脚本不更新表模型

iOS7 到 iOS8 应用程序文件迁移