使用WebAPI2,我有一个模型类,我在响应中对它进行序列化。 我想减少数据量。
我可以通过使用JsonProperty属性修饰模型的属性来做到这一点,这很好。
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore)]
public string AccountFee { get { return _accountFee; } set { _accountFee = value; } }
我已将DefaultValueHandling指定为Ignore,但我无法正确设置默认值。
文档说明在此属性修饰中使用首选默认值...
[DefaultValue("DEFAULTACCOUNT")]
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore)]
public string AccountFee { get { return _accountFee; } set { _accountFee = value; } }
但DefaultValue未解决。我无法弄清楚如何正确引用它。
我已经包含了使用Newtonsoft.Json和Newtonsoft.Json.Serialization的语句,但是仍然无法识别?我错过了命名空间,还是错误地使用了属性?