0

我正在使用 SSIS 脚本组件来执行 WEB API 的 C# 代码,该代码返回一个 Base64 编码字节和返回数组的值。

实际的返回值是一个编码的 JSON 字符串,我随后需要对其进行反序列化和输出。

我正在使用以下 C# 来尝试解码响应。

foreach (Attachment atch in rptOutputResponse.Response.attachments)
        {
            RptAttachmentsBuffer.AddRow();

            RptAttachmentsBuffer.AppId = rptOutputResponse.Response.appId;
            RptAttachmentsBuffer.Type = atch.type;
            RptAttachmentsBuffer.Name = atch.name;
            RptAttachmentsBuffer.ContentType = atch.contentType;

            byte[] rptConRaw = Encoding.UTF8.GetBytes(atch.content);

            String s = Convert.ToBase64String(rptConRaw);

            byte[] newbytes = Convert.FromBase64String(s);

            System.Windows.Forms.MessageBox.Show(BitConverter.ToString(newbytes));

            RptAttachmentsBuffer.ReportContent.AddBlobData(newbytes);

        }

预期的结果如下所示。

{"Applications":{"Application":{"AppID":2891426,"ReportID":4160202,"AppReference":"Taplin 12-Oct-16 10:37:02AM","CreateDT":"2016-10-12 10:37:23.3500000","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","Accounts":{"Account":[{"AccountID":4829641,"AccountNumber":"17-986-7500","AccountType":"savings","AccountName":"XXXXXXXXXXXX7500","AccountHolder

但是,当输出到我的桌子时,它是用日语传递的。我究竟做错了什么?

4

1 回答 1

0

请尝试以下方法:

foreach (Attachment atch in rptOutputResponse.Response.attachments)
{
    RptAttachmentsBuffer.AddRow();

    RptAttachmentsBuffer.AppId = rptOutputResponse.Response.appId;
    RptAttachmentsBuffer.Type = atch.type;
    RptAttachmentsBuffer.Name = atch.name;
    RptAttachmentsBuffer.ContentType = atch.contentType;

    byte[] newbytes = Convert.FromBase64String(atch.content);

    string json = Encoding.UTF8.GetString(newbytes);

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

    RptAttachmentsBuffer.ReportContent.AddBlobData(newbytes);

}
于 2016-11-29T06:09:20.373 回答