代码之家  ›  专栏  ›  技术社区  ›  Sujay U N

仅用于set或get的Asp Api JsonIgnore属性

  •  0
  • Sujay U N  · 技术社区  · 6 年前

    [JsonIgnore] 当我想同时排除set和get时,这是非常好的。

    public class NamTable
    {
        [JsonIgnore]
        public long id { get; set; }
        public string name { get; set; }
        public string mail { get; set; }
        public string mobile { get; set; }
        [JsonIgnore]
        public System.DateTime timestamp { get; set; }
    }
    

    例如 id timestamp 它们在插入或设置期间不需要,但我在执行get请求时需要它们。那么我需要添加哪些注释来实现这一点呢?

    public class NamTable
    {
        public long id { get; [JsonIgnore] set; }
        public string name { get; set; }
        public string mail { get; set; }
        public string mobile { get; set; }
    
        public System.DateTime timestamp { get; [JsonIgnore] set; }
    }
    
    0 回复  |  直到 6 年前