Arb*_*æde 2 asp.net json.net c#-4.0
我的class_中有string属性
[DataMember]
[JsonProperty(PropertyName = "email")]
[StringLength(40, ErrorMessage = "The Mobile value cannot exceed 40 characters. ")]
public string Email { get; set; }
Run Code Online (Sandbox Code Playgroud)
由于某种原因,在Convert.Deserialize过程中,我需要在此属性中使用空字符串而不是null,以防此值未在JSON对象中设置.怎么做 ?
您可以使用DefaultValue属性.
把它装饰成
[DataMember]
[JsonProperty(PropertyName = "email", DefaultValueHandling = DefaultValueHandling.Populate)]
[StringLength(40, ErrorMessage = "The Mobile value cannot exceed 40 characters. ")]
[DefaultValue("")]
public string Email { get; set; }
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8037 次 |
最近记录: |