小编use*_*307的帖子

当使用newtonsoft json.net反序列化字符串时,如何将空字符串转换为null为可空的int?

例如,如果我有

public class MyClass
{
    public Int32? Id { get;set; }
    public string Description { get;set; }
}
Run Code Online (Sandbox Code Playgroud)

我的json字符串看起来像这样:

"{\"Id\":\"\",\"Description\":\"test\"}"
Run Code Online (Sandbox Code Playgroud)

我收到错误"无法将字符串转换为整数"

c# nullable json.net

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

json.net ×1

nullable ×1