2016-11-29 136 views
0

我正在使用SSIS腳本組件爲Web API執行C#代碼,該API正在向我返回一個值,該值是一個Base64編碼的字節和返回數組。在C#中解碼Base64 HTTPWEBRESPONSE - 返回日語

實際返回值是一個編碼的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 

但是,當輸出到我的表,它是通過日語來通過。我究竟做錯了什麼?

+0

什麼的'atch.content'價值? – wdosanjos

+0

它應該是返回的編碼字符串。 eyJBcHBsaWNhdGlvbnMiOnsiQXBwbGljYXRpb24iOnsiQXBwSUQiOjI4OTE0MjYsIlJlcG9ydElEIjo0MTYwMjAyLCJBcHBSZWZlcmVuY2UiOiJUYXBsaW4gMTItT2N0LTE2IDEwOjM3OjAyQU0iLCJDcmVhdGVEVCI6IjIwMTYtMTAtMTIgMTA6Mz ... –

回答

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

} 
+0

你是我的新寵人。謝謝! –

+1

@wdosanjos,應該用json替換newbytes! –

+0

@MukeshModhvadiya謝謝。我修復了缺失的'newbytes'變量。 – wdosanjos