enum & json 之间的转换

enum 转为 string:EnumMember & StringEnumConverter

 public enum CampaignStatus : Int32
{
[EnumMember(Value = "Running")]
Running = 1,
[EnumMember(Value = "Archived")]
Archived = 2,
[EnumMember(Value = "NotRunning")]
NotRunning = 3
}
        /// <summary>
/// optional
/// </summary>
[JsonProperty("campaignStatus")]
[JsonConverter(typeof(StringEnumConverter))]
public CampaignStatus? CampaignStatus { get; set; }

    

enum array 转为string array:StringEnumConverter & JsonProperty

       [JsonProperty(PropertyName = "Status", ItemConverterType = typeof(StringEnumConverter))]
public CampaignStatus[] Status { get; set; }

dll引用:

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

  

上一篇:python 字典的函数


下一篇:Oracle 查看占用undo大的sql语句