I am trying to parse the return JSON statement from an online credit card company. The result Json I get back is the following (please note this is from their sandbox using their sample data).
{
"transactionResponse": {
"responseCode": "1",
"authCode": "X4OMIZ",
"avsResultCode": "Y",
"cvvResultCode": "P",
"cavvResultCode": "2",
"transId": "60197979609",
"refTransID": "",
"transHash": "",
"testRequest": "0",
"accountNumber": "XXXX0015",
"accountType": "MasterCard",
"messages": [{
"code": "1",
"description": "This transaction has been approved."
}],
"transHashSha2": "E7F434A59456910F0CF72AAF0A3031C06AA5F28746BF7895B8794A4BA60EA0C7586A2C08259BB78B4E05DAD67242478C53A3FA6600B7B5BBB213304735D5E32B",
"SupplementalDataQualificationIndicator": 0,
"networkTransId": "MFKPNF0T4KGJ82HIEF8VHN6"
},
"refId": "MO2000003-12",
"messages": {
"resultCode": "Ok",
"message": [{
"code": "I00001",
"text": "Successful."
}]
}
}
When I use the following code;
JSONPackage ljp_pkg
ljp_pkg = CREATE JSONPackage
// load the entire json result set
ls_ret = ljp_pkg.loadstring(as_result) // as_result is a string set to the json above
// get the json section for messages only
ls_json = ljp_pkg.getvalue("messages")
At this point ls_json = {"resultCode":"Ok","message":[{"code":"I00001","text":"Successful."}]}
I do not understand why it is not [{"code":"1","description":"This transaction has been approved."}] which is the first instance of the work message in the return Json. I even tried stripping out the [ ] from the string and it still goes to the second key of message. The instructions for GetValue state that it will return the first instance.
Any idea?