You've got up to 6M bytes of heap to play with (and I think a maximum HTTP body size of 3M bytes) so if say the base64 version of all the images is always smaller than say a couple of Mbytes then sending them all at once should be OK.
String has an indexOf method that you could use to work through each block of base64 in turn first finding a '[imgData]' and then the following '[/imgData]' and using substring you can pull out the text in between without hitting the regex problem.
As sfdcfox suggested in a comment, you can use json2apex to generate the necessary code from a JSON sample. The app is a little out of date in that test methods should now be in a different class, so I generated the code and separated out the test method:
UserAgreements Class
public class UserAgreements {
public class DisplayUserInfo {
public String company;
public String fullNameOrEmail;
}
public List<UserAgreementList> userAgreementList;
public class UserAgreementList {
public String displayDate;
public DisplayUserInfo displayUserInfo;
public Boolean esign;
public String agreementId;
public String latestVersionId;
public String name;
public String status;
}
public static UserAgreements parse(String json) {
return (UserAgreements) System.JSON.deserialize(json, UserAgreements.class);
}
}
UserAgreementsTest Class
@isTest
public class UserAgreementsTest {
static testMethod void testParse() {
String json = '{'+
' \"userAgreementList\": ['+
' {'+
' \"displayDate\": \"2015-04-02T09:32:23-07:00\",'+
' \"displayUserInfo\": {'+
' \"company\": \"TEST\",'+
' \"fullNameOrEmail\": \"Tim 1234\"'+
' },'+
' \"esign\": true,'+
' \"agreementId\": \"AGREEMENT ID\",'+
' \"latestVersionId\": \"VERSION ID\",'+
' \"name\": \"Agreement for APEX Test Account - 2015-04-02\",'+
' \"status\": \"OUT_FOR_SIGNATURE\"'+
' },'+
' {'+
' \"displayDate\": \"2015-04-02T03:32:57-07:00\",'+
' \"displayUserInfo\": {'+
' \"company\": \"TEST\",'+
' \"fullNameOrEmail\": \"Tim 1234\"'+
' },'+
' \"esign\": true,'+
' \"agreementId\": \"AGREEMENT ID\",'+
' \"latestVersionId\": \"VERSION ID\",'+
' \"name\": \"Agreement for APEX Test Account - 2015-04-02\",'+
' \"status\": \"OUT_FOR_SIGNATURE\"'+
' },'+
' {'+
' \"displayDate\": \"2015-03-31T09:15:11-07:00\",'+
' \"displayUserInfo\": {'+
' \"company\": \"TEST\",'+
' \"fullNameOrEmail\": \"Tim 1234\"'+
' },'+
' \"esign\": true,'+
' \"agreementId\": \"AGREEMENT ID\",'+
' \"latestVersionId\": \"VERSION ID\",'+
' \"name\": \"Agreement for APEX Test Account - 2015-04-02\",'+
' \"status\": \"RECALLED\"'+
' }'+
' ]'+
'}';
UserAgreements obj = UserAgreements.parse(json);
System.assert(obj != null);
}
}
Best Answer
So, the response you are receiving is a JSON string. You can parse it like this:
Then, you can access it like this: