Newtonsoft.Json高级用法
-
- 忽略某些属性
仅需要姓名属性
[JsonObject(MemberSerialization.OptIn)] public class Person { public int Age { get; set; } [JsonProperty] public string Name { get; set; } public string Sex { get; set; } public bool IsMarry { get; set; } public DateTime Birthday { get; set; } }
不需要是否结婚属性
[JsonObject(MemberSerialization.OptOut)] public class Person { public int Age { get; set; } public string Name { get; set; } public string Sex { get; set; } [JsonIgnore] public bool IsMarry { get; set; } public DateTime Birthday { get; set; } }
- 忽略某些属性