反序列化的JSON使用空格重用C#类

时间:2017-04-26 04:05:26

标签: c# sql-server json visual-studio-2010 ssis

我正在使用来自作为Base64编码返回的REST API的HTTPWebResponse。当我解码它似乎Deserialise罚款然而当我创建clasess我有无效的名称,并在其中有空格。

我已经尝试过JsonObject和JsonProperty,但我似乎没有Visual Studio 2010和SQL Server 2008 R2(SSIS)中的可用引用和名称空间,我无法弄清楚如何通过它。

这是一个交易详细信息文件,因此非常大,无法在此处发布。我想知道是否有人可以指出如何加载正确的引用以使用上述方法,或者告诉我如何使用空格读取Json标记,并仍然在SSIS中的c#脚本组件中有效地声明它们。

示例:回应:

            "High Risk Merchants": {
              "High Risk Merchants": [
                {
                  "AccountID": 4829640,
                  "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#类声明(json2csharp)

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

public class HighRiskMerchants
{
    public List<HighRiskMerchant> __invalid_name__High Risk Merchants { get; set; }
}

DATA输出调用

 foreach (HighRiskMerchant hrm in ac.Overviews.Overview.HighRiskMerchants.HighRiskMerchantEntity)
            {
                RptOverviewDataBuffer.AddRow();
                RptOverviewDataBuffer.Type = "HighRiskMerchants";
                RptOverviewDataBuffer.SubType = "HighRiskMerchantsEntity";
                RptOverviewDataBuffer.AccountID = Convert.ToInt32(hrm.AccountID);
                RptOverviewDataBuffer.H1 = hrm.H1;
                RptOverviewDataBuffer.H2 = hrm.H2;
                RptOverviewDataBuffer.H3 = hrm.H3;
                RptOverviewDataBuffer.SH1 = hrm.SH1;
                RptOverviewDataBuffer.Description = hrm.Description;
                RptOverviewDataBuffer.Count = Convert.ToInt32(hrm.Count);
                RptOverviewDataBuffer.FrequencyDescription = hrm.FrequencyDescription;
                RptOverviewDataBuffer.FrequencyDuration = hrm.FrequencyDuration;
                RptOverviewDataBuffer.FrequencyDurationDate = hrm.FrequencyDurationDate;
                RptOverviewDataBuffer.FrequencyWeekday = hrm.FrequencyWeekday;
                RptOverviewDataBuffer.FrequencyAmount = Convert.ToDouble(hrm.FrequencyAmount);
                RptOverviewDataBuffer.FrequencyAmountRange = hrm.FrequencyAmountRange;
                RptOverviewDataBuffer.TotalAmount = Convert.ToDouble(hrm.TotalAmount);
                RptOverviewDataBuffer.TotalInAmount = Convert.ToDouble(hrm.TotalInAmount);
                RptOverviewDataBuffer.TotalOutAmount = Convert.ToDouble(hrm.TotalOutAmount);
                RptOverviewDataBuffer.MonthlyAmount = Convert.ToDouble(hrm.MonthlyAmount);
                RptOverviewDataBuffer.GroupID = hrm.GroupID;
                RptOverviewDataBuffer.Display = hrm.Display;
                RptOverviewDataBuffer.FrequencyExactness = hrm.FrequencyExactness;
                RptOverviewDataBuffer.FrequencyPeriod = hrm.FrequencyPeriod;
                RptOverviewDataBuffer.ScoreEmployer = Convert.ToInt32(hrm.ScoreEmployer);
                RptOverviewDataBuffer.ScoreDirCr = Convert.ToInt32(hrm.ScoreDirCr);
                RptOverviewDataBuffer.ScoreWeekday = hrm.ScoreWeekday;
                RptOverviewDataBuffer.ScoreFrequency = hrm.ScoreFrequency;
                RptOverviewDataBuffer.ScoreAmount = Convert.ToDouble(hrm.ScoreAmount);
                RptOverviewDataBuffer.ScoreTotal = Convert.ToInt32(hrm.ScoreTotal);
            }

1 个答案:

答案 0 :(得分:1)

要使用的库,您可以使用nuget install "Json.Net"

在这个例子中,它将是:

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