解析对C#对象的Json响应时,请跳过Nullable int

问题描述

我正在解析对c#对象的json响应

我的模型

public class OutstandingPrompts
{
    public int? PatientID { get; set; }
    public int? AlertTypeID { get; set; }
    public int? PatientAlertID { get; set; }
    public int? PriorityID { get; set; }
    public string PriorityColor { get; set; }
    public string Priority { get; set; }
    public string AlertType { get; set; }
    public DateTime? RecallDate { get; set; }
    public string ForSmoking { get; set; }
    public string Note { get; set; }
    public string AlertValue { get; set; }
    public string AlertGroup { get; set; }
    public DateTime? EXPIRYDATE { get; set; }
    public string FullName { get; set; }
    public string ProviderName { get; set; }
    public int? AlertCategory { get; set; }
    public int? IsConfidential { get; set; }
    public int? ConfidentialViewLogID { get; set; }
    public int? Completed { get; set; }
    public int? TotalRecords { get; set; }
}

这就是我的转换方式

List<OutstandingPrompts> b = xs.Value.ElementAt(0).ElementAt(0).ToObject<List<OutstandingPrompts>>();

它工作正常,因为我在模型中将int类型设置为可为null的int?因为int类型可能存在null值

现在我在想什么,有没有办法在不将我的int类型设置为可空的情况下解析json 。我知道的一种方法是在检查结果为空时循环遍历它,然后不分配值,但是有没有另一种不用编写自己的逻辑的方法?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...