JSON中的重复对象名称

时间:2017-06-01 22:26:55

标签: c# json ssis .net-4.0

我正在处理我正在回复的API响应,看起来像这样。 我有一个问题反序列化部分由于嵌套级别具有相同的标识符而无法在C#类中将它们命名为相同。

"Dishonours": { "Dishonours": [ { "AccountID": 5292142, "H1": "Dishonours", "H2": "Dishonours", "H3": "", "SH1": "", "Description": "{No Unique Description} (DIR DR RVSL,DIR DR RVSL FEE)", "Count": 2, "FrequencyDescription": "Infrequent Same Day", "FrequencyDuration": "", "FrequencyDurationDate": "24Oct", "FrequencyWeekday": "", "FrequencyAmount": 47.2, "FrequencyAmountRange": "(6-88)", "TotalAmount": 94.4, "TotalInAmount": 88.4, "TotalOutAmount": 6, "MonthlyAmount": 0, "GroupID": "0-1130", "Display": "{No Unique Description}", "FrequencyExactness": "Infrequent", "FrequencyPeriod": "Same Day", "ScoreEmployer": null, "ScoreDirCr": null, "ScoreWeekday": null, "ScoreFrequency": null, "ScoreAmount": null, "ScoreTotal": 0 } ] }, "High Risk Merchants": { "High Risk Merchants": [ { "AccountID": 5292142, "H1": "High Risk Merchants", "H2": "High Risk Merchants", "H3": "", "SH1": "", "Description": "{NO MATCH}", "Count": null, "FrequencyDescription": null, "FrequencyDuration": null, "FrequencyDurationDate": null, "FrequencyWeekday": null, "FrequencyAmount": null, "FrequencyAmountRange": null, "TotalAmount": null, "TotalInAmount": null, "TotalOutAmount": null, "MonthlyAmount": null, "GroupID": null, "Display": null, "FrequencyExactness": null, "FrequencyPeriod": null, "ScoreEmployer": null, "ScoreDirCr": null, "ScoreWeekday": null, "ScoreFrequency": null, "ScoreAmount": null, "ScoreTotal": null } ] }

我已经声明了我的C#类,但我仍然得到一个空引用错误,因为它不会拿起嵌套标记。

这就是我对此进行反序列化的方式。

private RootObjectContent DeserializeReportContent(string reportAttachmentContent)
{
    RootObjectContent attachedReportContent = null;

    string reportContentString = null;

    //System.Windows.Forms.MessageBox.Show(rptJsonContent.Replace(@"\", ""));

    using (StringReader contentReader = new StringReader(reportAttachmentContent.Replace(@"\", "")))
    {
        reportContentString = contentReader.ReadToEnd().ToString();
    }

    System.Windows.Forms.MessageBox.Show(reportContentString);

    JavaScriptSerializer returnRptContent = new JavaScriptSerializer();
    var serialContentJsonStr = returnRptContent.Serialize(reportContentString);

    attachedReportContent = returnRptContent.Deserialize<RootObjectContent>(reportContentString.Replace(@"\", ""));

    return attachedReportContent;

}

我只能在Visual Studio 2010(.NET 4.0)中使用SSIS,因此无法使用Newtonsoft 10.0.0.0版。

到底有没有?

public class Dishonour
{
    [JsonProperty("AccountID")]
    public int? AccountID { get; set; }
    [JsonProperty("H1")]
    public string H1 { get; set; }
    [JsonProperty("H2")]
    public string H2 { get; set; }
    [JsonProperty("H3")]
    public string H3 { get; set; }
    [JsonProperty("SH1")]
    public string SH1 { get; set; }
    [JsonProperty("Description")]
    public string Description { get; set; }
    [JsonProperty("Count")]
    public int? Count { get; set; }
    [JsonProperty("FrequencyDescription")]
    public string FrequencyDescription { get; set; }
    [JsonProperty("FrequencyDuration")]
    public string FrequencyDuration { get; set; }
    [JsonProperty("FrequencyDurationDate")]
    public string FrequencyDurationDate { get; set; }
    [JsonProperty("FrequencyWeekday")]
    public string FrequencyWeekday { get; set; }
    [JsonProperty("FrequencyAmount")]
    public decimal? FrequencyAmount { get; set; }
    [JsonProperty("FrequencyAmountRange")]
    public string FrequencyAmountRange { get; set; }
    [JsonProperty("TotalAmount")]
    public decimal? TotalAmount { get; set; }
    [JsonProperty("TotalInAmount")]
    public decimal? TotalInAmount { get; set; }
    [JsonProperty("TotalOutAmount")]
    public decimal? TotalOutAmount { get; set; }
    [JsonProperty("MonthlyAmount")]
    public decimal? MonthlyAmount { get; set; }
    [JsonProperty("GroupID")]
    public string GroupID { get; set; }
    [JsonProperty("Display")]
    public string Display { get; set; }
    [JsonProperty("FrequencyExactness")]
    public string FrequencyExactness { get; set; }
    [JsonProperty("FrequencyPeriod")]
    public string FrequencyPeriod { get; set; }
    [JsonProperty("ScoreEmployer")]
    public int? ScoreEmployer { get; set; }
    [JsonProperty("ScoreDirCr")]
    public int? ScoreDirCr { get; set; }
    [JsonProperty("ScoreWeekday")]
    public int? ScoreWeekday { get; set; }
    [JsonProperty("ScoreFrequency")]
    public int? ScoreFrequency { get; set; }
    [JsonProperty("ScoreAmount")]
    public int? ScoreAmount { get; set; }
    [JsonProperty("ScoreTotal")]
    public int? ScoreTotal { get; set; }
}

public class Dishonours
{
    [JsonProperty("Dishonours")]
    public List<Dishonour> Dishonour { get; set; }
}

public class HighRiskMerchant
{
    [JsonProperty("AccountID")]
    public int? AccountID { get; set; }
    [JsonProperty("H1")]
    public string H1 { get; set; }
    [JsonProperty("H2")]
    public string H2 { get; set; }
    [JsonProperty("H3")]
    public string H3 { get; set; }
    [JsonProperty("SH1")]
    public string SH1 { get; set; }
    [JsonProperty("Description")]
    public string Description { get; set; }
    [JsonProperty("Count")]
    public int? Count { get; set; }
    [JsonProperty("FrequencyDescription")]
    public string FrequencyDescription { get; set; }
    [JsonProperty("FrequencyDuration")]
    public string FrequencyDuration { get; set; }
    [JsonProperty("FrequencyDurationDate")]
    public string FrequencyDurationDate { get; set; }
    [JsonProperty("FrequencyWeekday")]
    public string FrequencyWeekday { get; set; }
    [JsonProperty("FrequencyAmount")]
    public double? FrequencyAmount { get; set; }
    [JsonProperty("FrequencyAmountRange")]
    public string FrequencyAmountRange { get; set; }
    [JsonProperty("TotalAmount")]
    public double? TotalAmount { get; set; }
    [JsonProperty("TotalInAmount")]
    public double? TotalInAmount { get; set; }
    [JsonProperty("TotalOutAmount")]
    public double? TotalOutAmount { get; set; }
    [JsonProperty("MonthlyAmount")]
    public double? MonthlyAmount { get; set; }
    [JsonProperty("GroupID")]
    public string GroupID { get; set; }
    [JsonProperty("Display")]
    public string Display { get; set; }
    [JsonProperty("FrequencyExactness")]
    public string FrequencyExactness { get; set; }
    [JsonProperty("FrequencyPeriod")]
    public string FrequencyPeriod { get; set; }
    [JsonProperty("ScoreEmployer")]
    public int? ScoreEmployer { get; set; }
    [JsonProperty("ScoreDirCr")]
    public int? ScoreDirCr { get; set; }
    [JsonProperty("ScoreWeekday")]
    public string ScoreWeekday { get; set; }
    [JsonProperty("ScoreFrequency")]
    public string ScoreFrequency { get; set; }
    [JsonProperty("ScoreAmount")]
    public double? ScoreAmount { get; set; }
    [JsonProperty("ScoreTotal")]
    public int? ScoreTotal { get; set; }
}

public class HighRiskMerchants
{
    [JsonProperty("High Risk Merchants")]
    public List<HighRiskMerchants> HighRiskMerchant { get; set; }
}

0 个答案:

没有答案