如果c#中的整数值为0,则忽略对象的属性
c#
如果整数属性为 0 忽略它,来自 json 对象。
[JsonProperty("amount")]
public int Amount { get; set; }
我不想在应用程序中全局应用它。
回答
这可以使用Json-Ignore 属性来实现。
代码将是:
[JsonProperty("amount")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public int Amount { get; set; }