Lists from Json
Posted: Fri Dec 06, 2019 3:55 pm
How do you read an item from a list in a hash created from a json response.
Look for the "[" in the example response below:
If I used hb_JsonDecode( cJsonResponse,@o )
Then how do I get the second set of variables from the hash?
o["transactionResponse"]["userFields"]["name"]
How do I get to the second set of "name/value" in this hash.
{
"transactionResponse": {
"responseCode": "1",
"authCode": "C1E3I6",
"avsResultCode": "Y",
"cvvResultCode": "S",
"cavvResultCode": "9",
"transId": "2149186775",
"refTransID": "",
"transHash": "C85B15CED28462974F1114DB07A16C39",
"accountNumber": "XXXX0015",
"accountType": "Mastercard",
"messages": [
{
"code": "1",
"description": "This transaction has been approved."
}
],
"userFields": [
{
"name": "MerchantDefinedFieldName1",
"value": "MerchantDefinedFieldValue1"
},
{
"name": "favorite_color",
"value": "blue"
}
]
},
"refId": "123456",
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}
Thanks,
Byron ...
Look for the "[" in the example response below:
If I used hb_JsonDecode( cJsonResponse,@o )
Then how do I get the second set of variables from the hash?
o["transactionResponse"]["userFields"]["name"]
How do I get to the second set of "name/value" in this hash.
{
"transactionResponse": {
"responseCode": "1",
"authCode": "C1E3I6",
"avsResultCode": "Y",
"cvvResultCode": "S",
"cavvResultCode": "9",
"transId": "2149186775",
"refTransID": "",
"transHash": "C85B15CED28462974F1114DB07A16C39",
"accountNumber": "XXXX0015",
"accountType": "Mastercard",
"messages": [
{
"code": "1",
"description": "This transaction has been approved."
}
],
"userFields": [
{
"name": "MerchantDefinedFieldName1",
"value": "MerchantDefinedFieldValue1"
},
{
"name": "favorite_color",
"value": "blue"
}
]
},
"refId": "123456",
"messages": {
"resultCode": "Ok",
"message": [
{
"code": "I00001",
"text": "Successful."
}
]
}
}
Thanks,
Byron ...