簡體   English   中英

用C#解碼Base64 HTTPWEBRESPONSE-返回日語

[英]Decode Base64 HTTPWEBRESPONSE in C# - Returns Japanese

我正在使用SSIS腳本組件為WEB API執行C#代碼,該Web 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

但是,當輸出到我的表時,它是日語的。 我究竟做錯了什么?

請嘗試以下操作:

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);

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM