0

I am using an SSIS Script Component to execute C# code for a WEB API that is returning me a value that is a Base64 Encoded byte un a return array.

The actual return value is an encoded JSON string which I subsequently need to deserialize and output.

I am using the following C# to try and decode the response.

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

        }

The expected result looks like this.

{"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

However when output to my table it is coming through in Japanese. What am I doing wrong?

Lucas Perrett
  • 423
  • 1
  • 6
  • 16
  • What's the value of `atch.content`? – Wagner DosAnjos Nov 29 '16 at 05:57
  • it should be the encoded string that is returned. eyJBcHBsaWNhdGlvbnMiOnsiQXBwbGljYXRpb24iOnsiQXBwSUQiOjI4OTE0MjYsIlJlcG9ydElEIjo0MTYwMjAyLCJBcHBSZWZlcmVuY2UiOiJUYXBsaW4gMTItT2N0LTE2IDEwOjM3OjAyQU0iLCJDcmVhdGVEVCI6IjIwMTYtMTAtMTIgMTA6Mz... – Lucas Perrett Nov 29 '16 at 06:00

1 Answers1

1

Please try the following:

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

}
Wagner DosAnjos
  • 6,304
  • 1
  • 15
  • 29