一、实体书写
将枚举类型的属性前面加上[JsonConverter(typeof(StringEnumConverter))]即可。
二、举例
[JsonConverter(typeof(StringEnumConverter))] public CheckTypeEnum checkType { get; set; } public int num { get; set; } [JsonConverter(typeof(StringEnumConverter))] public InputTypeEnum type { get; set; }
四、结果
另外,如果需要变更属性的名称,则在前面添加[JsonProperty(PropertyName = “newName”)]:
[JsonProperty(PropertyName = "newName")] public string key { get; set; }