相关疑难解决方法(0)

System.Text.Json:如何为枚举值指定自定义名称?

使用.NET Core 中的System.Text.Json序列化器功能,如何为枚举值指定自定义值,类似于JsonPropertyName? 例如:

public enum Example {
  Trick, 
  Treat, 
  [JsonPropertyName("Trick-Or-Treat")] // Error: Attribute 'JsonPropertyName' is not valid on this declaration type. It is only valid on 'property, indexer' declarations.
   TrickOrTreat
}
Run Code Online (Sandbox Code Playgroud)

.net c# .net-core .net-core-3.0 system.text.json

22
推荐指数
1
解决办法
2万
查看次数

标签 统计

.net ×1

.net-core ×1

.net-core-3.0 ×1

c# ×1

system.text.json ×1