Serialize enum as a string in JSON.NET using attributes

前端 未结 1 602
失恋的感觉
失恋的感觉 2020-12-19 04:10

I want to serialize enum as string using JSON.NET using attributes similar to [JsonIgnore]

Example class:

enum Gender { Male, Female }
c         


        
相关标签:
1条回答
  • 2020-12-19 04:25

    Have a look at [JsonConverter(typeof(StringEnumConverter))]. Should do what you want.

    Edit: http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_Converters_StringEnumConverter.htm provides some info.

    0 讨论(0)
提交回复
热议问题