0

How to parse the HTTP Response if response string is in name value pair.

RESULT=0&PNREF=EFHP0D426A53&RESPMSG=APPROVED&AUTHCODE=25TEST&AVSADDR=Y&AVSZIP=N&CVV2MATCH=Y

1 Answer 1

2

There are many ways to parse it, but probably the simplest is to use String.split. Something like the following should get you started.

Map<String, String> payload = new Map<String, String>();
for (String pair : response.getBody().split('&'))
{
    List<String> data = pair.split('=', 2);
    String key = data[0], value = (data.size() > 1) ? data[1] : null;
    payload.put(key, value);
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .