在C#中解码Base64 HTTPWEBRESPONSE - 返回日语

时间:2016-11-29 05:51:37

标签: c# sql-server json ssis script-component

我正在使用SSIS脚本组件为WEB API执行C#代码,该API返回一个值为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

然而,当输出到我的桌子时,它将以日语发送。我做错了什么?

1 个答案:

答案 0 :(得分: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);

}