Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

We are calling an External WebService that is returning us the JSON Object. In that Json Object they are sending the PDF as ByteArray(JsonArray) not as Base64 String. So am thinking is there a way to convert that ByteArray/JsonArray to Base64 String that will allow us to make PDF in SFDC end.

Sample Response Json we are getting.(The actual Array is too huge, i have removed some array values just to post it here)

{"FINISHED":[[37,80,68,70,45,49,46,52,10,37,-57,-27,-12,-27,-16,10,51,32,48,32]]}

share|improve this question

1 Answer 1

Create a response Object like this

public class Resp {
    public List<List<Integer>> FINISHED { get; set; }
}

then do

Resp r = (Resp) JSON.deserialize(jsonString, Resp.class);

and then finally convert the r.FINISHED into a Blob

List<Integer> values = r.FINISHED.get(0);
String encodedString = String.fromCharArray(values);
Blob someFile = EncodingUtil.base64Decode(encodedString);

(Thanks to @Bachovski for pointing to the fromCharArray function)

share|improve this answer
    
Converting the bytes to characters in 2 lines: List <Integer> charArr = new List <Integer> {97,65}; String resultString = String.fromCharArray(charArr); –  Bachovski 21 hours ago
    
Tried.. its Giving me System.StringException: Unrecognized base64 character: % –  susanoo chidori 18 hours ago
    
What does encodedString look like? –  Willem Mulder 16 hours ago
    
Encoded String looked like. %PDF-1.4 %ᅦ¥￴¥￰ 3 0 –  susanoo chidori 15 hours ago
    
What happens if you do Blob.valueof(encodedString); ? –  Willem Mulder 14 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.