Newtonsoft Json Property

201 阅读1分钟

Ignore null value Link

[JsonProperty("property_name", NullValueHandling = NullValueHandling.Ignore)]

Ignore property

[JsonIgnore]

Default value for property

 [DefaultValue(5)]            
 [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
 public int Age { get; private set; }

Multiple property

[DefaultValue(DefaultText)]
[JsonProperty(PropertyName = "myText", DefaultValueHandling = DefaultValueHandling.Populate)]
public readonly string Text;

Enum

[JsonConverter(typeof(StringEnumConverter))]
public enum StatusType
{
    [EnumMember(Value = "A")]
    All,
    [EnumMember(Value = "I")]
    InProcess,
    [EnumMember(Value = "C")]
    Complete,
}