经常在使用过程中出现接口或其他代码中出现序列化过来的数据包字段命名很不规范的场景,但在C#中,又比较介意这种不规范的命名,所以尝试看看能不能通过别名的方式实现。


1:JSON工具:Newtonsoft.Json

2:实现方式:

    通过注解:JsonProperty 中的 PropertyName 属性来实现别名

3:举例:

    
    public class Student {
        [JsonProperty(PropertyName ="ID")]
        public int id;
        [JsonProperty(PropertyName ="XName")]
        public string name;
    }

   序列化:

    Json 序列化中使用字段别名

   反序列化:

    Json 序列化中使用字段别名

    


相关文章:

  • 2022-12-23
  • 2021-11-10
  • 2021-12-06
  • 2021-09-24
  • 2021-10-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-21
相关资源
相似解决方案