zoukankan      html  css  js  c++  java
  • 使用Newtonsoft进行JSON序列化时将枚举序列化为字符串的方法

    一、实体书写

      将枚举类型的属性前面加上[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; }
  • 相关阅读:
    6-1
    4-9
    4-5
    4-4
    4-3
    3-10
    作业三2
    作业三1
    课堂练习二
    实验三
  • 原文地址:https://www.cnblogs.com/songxingzhu/p/8665063.html
Copyright © 2011-2022 走看看