2016-11-29 25 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