The condition setting sequence of [JsonIgnore]

Use name ShouldSerialize {PropertyName} defining a common method, the method will return bool within the class. May determine whether the sequence of fields in accordance with PropertyName return bool value.

Such as:

public int Age{get;set;}

public string Name{get;set;}

public bool ShouldSerializeName(){

   return  !string.IsNullOrEmpty(Name);

}

When the return sequence of name is an empty string {Age: X,}, the sequence returns when the name of the string is not empty {Age: X, Name: 'XXX'},

Guess you like

Origin www.cnblogs.com/a976986319/p/12425267.html