简体   繁体   中英

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:

[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.
I want set this null value to empty, how can I achieve this?
I've tryed also with: [DefaultValue("Null")] but don't working because the value is an integer.

将int设置为nullablenullable尝试如下:

public int? jerseyNumber { get; set; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM