1

我正在尝试返回如下所示的 JSON 数据集。让我提醒一下,我仅限于 Visual Studio 2010 和 .NET 4.0。如何输出 NULL 或转换为空白?

  "Application": {
  "AppID": 3119385,
  "ReportID": 4171130,
  "AppReference": "Doran 23-Nov-16 10:46:59AM",
  "CreateDT": "2016-11-23 10:48:38.5800000",
  "ClientName": "GoGetta Brisbane",
  "StoreName": "Brokers",
  "Email": "",
  "StoreCode": "GGT08",
  "AppShortReference": "02",
  "ClientNameShort": "GGT Bris",
  "StoreNameShort": "GGT08",
  "VerifyEmployer": null,
  "VerifyAmount": null,
  "VerifyFrequency": null,
  "VerifyWeekday": null,
  "LocalityCode": "en_AU",
  "TemplateReportID": 12,
  "daysRange": 90,
  "templateReportName": "Enhanced Income Liabilities Full Report",
  "isReportGraphEnabled": 1,

我正在尝试将其处理为 SSIS 中脚本组件的输出缓冲区。但是,尽管进行了检查,但我仍然收到“无法将 null 转换为值类型”错误。

  if (String.IsNullOrEmpty(rptContentOutput.Applications.Application.VerifyEmployer) == true)
            {
                ApplicationDetailsBuffer.VerifyEmployer = "";
            }
            else
            {
                ApplicationDetailsBuffer.VerifyEmployer = rptContentOutput.Applications.Application.VerifyEmployer;
            }

我的班级被定义如下。

public class Application
{
    [JsonProperty("AppID")]
    public int? AppID { get; set; }
    [JsonProperty("ReportID")]
    public int? ReportID { get; set; }
    [JsonProperty("AppReference")]
    public string AppReference { get; set; }
    [JsonProperty("CreateDT")]
    public string CreateDT { get; set; }
    [JsonProperty("ClientName")]
    public string ClientName { get; set; }
    [JsonProperty("StoreName")]
    public string StoreName { get; set; }
    [JsonProperty("Email")]
    public string Email { get; set; }
    [JsonProperty("StoreCode")]
    public string StoreCode { get; set; }
    [JsonProperty("AppShortReference")]
    public string AppShortReference { get; set; }
    [JsonProperty("ClientNameShort")]
    public string ClientNameShort { get; set; }
    [JsonProperty("StoreNameShort")]
    public string StoreNameShort { get; set; }
    [JsonProperty("VerifyEmployer")]
    public string VerifyEmployer { get; set; }
    [JsonProperty("VerifyAmount")]
    public double VerifyAmount { get; set; }
    [JsonProperty("VerifyFrequency")]
    public string VerifyFrequency { get; set; }
    [JsonProperty("VerifyWeekday")]
    public string VerifyWeekday { get; set; }
    [JsonProperty("LocalityCode")]
    public string LocalityCode { get; set; }
    [JsonProperty("TemplateReportID")]
    public int? TemplateReportID { get; set; }
    [JsonProperty("daysRange")]
    public int? daysRange { get; set; }
    [JsonProperty("templateReportName")]
    public string templateReportName { get; set; }
    [JsonProperty("isReportGraphEnabled")]
    public string isReportGraphEnabled { get; set; }

}

4

1 回答 1

1

好的,我用之前的评论误读了代码,但我现在看到了。

问题是:

public double VerifyAmount { get; set; }

这是一个值类型,JSON 包含:

"VerifyAmount": null,

这会导致错误。修复方法是:

public double? VerifyAmount { get; set; }
于 2017-05-31T00:26:25.703 回答