[英]How to set default value instead of null in deserialization
After a deserialization I get some object null, this cause an exception in the deserialization so I've avoided the problem setting the appropriate property in the class: 反序列化后,我得到一些对象为null,这会在反序列化中导致异常,因此我避免了在类中设置适当属性的问题:
[JsonProperty("jerseyNumber", NullValueHandling = NullValueHandling.Ignore)]
public int jerseyNumber { get; set; }
The problem is that after the deserialization, the value of the int
is equal to 0 because in the JSON is null. 问题在于,反序列化之后,
int
的值等于0,因为JSON中的值为null。
I want set this null
value to empty, how can I achieve this? 我想将此
null
值设置为空,如何实现呢?
I've tryed also with: [DefaultValue("Null")]
but don't working because the value is an integer. 我也尝试过使用:
[DefaultValue("Null")]
但由于值是整数而无法正常工作。
将int设置为nullable
为nullable
尝试如下:
public int? jerseyNumber { get; set; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.