I need to get some elements inside a Javascript JSON framework. I can get unit elements like this:
alert(response.paymentMethods.CREDIT_CARD.options.MASTERCARD.images.SMALL.path);
alert(response.paymentMethods.CREDIT_CARD.options.VISA.images.SMALL.path);
But I need to make a loop to capture ALL of these "SMALL" paths of ALL card types. I have tried in many ways but they always return me error or undefined .
I've even followed the steps from this site that would be exactly what I need, but without success.
Javascript :
PagSeguroDirectPayment.getPaymentMethods({
success: function(response) {
//meios de pagamento disponíveis
},
error: function(response) {
//tratamento do erro
},
complete: function(response) {
//tratamento comum para todas chamadas
}
});
JSON :
{
"error":false,
"paymentMethods":{
"BOLETO":{
"name":"BOLETO",
"options":{
"BOLETO":{
"name":"BOLETO",
"displayName":"Boleto",
"status":"AVAILABLE",
"code":202,
"images":{
"SMALL":{
"size":"SMALL",
"path":"/public/img/payment-methods-flags/42x20/booklet.png"
},
"MEDIUM":{
"size":"MEDIUM",
"path":"/public/img/payment-methods-flags/68x30/booklet.png"
}
}
}
},
"code":2
},
"ONLINE_DEBIT":{
"name":"ONLINE_DEBIT",
"options":{
"BANCO_BRASIL":{
"name":"BANCO_BRASIL",
"displayName":"Banco do Brasil",
"status":"AVAILABLE",
"code":304,
"images":{
"SMALL":{
"size":"SMALL",
"path":"/public/img/payment-methods-flags/42x20/bb.png"
},
"MEDIUM":{
"size":"MEDIUM",
"path":"/public/img/payment-methods-flags/68x30/bb.png"
}
}
},
},
"code":3
},
"CREDIT_CARD":{
"name":"CREDIT_CARD",
"options":{
"MASTERCARD":{
"name":"MASTERCARD",
"displayName":"MasterCard",
"status":"AVAILABLE",
"code":102,
"images":{
"SMALL":{
"size":"SMALL",
"path":"/public/img/payment-methods-flags/42x20/mastercard.png"
},
"MEDIUM":{
"size":"MEDIUM",
"path":"/public/img/payment-methods-flags/68x30/mastercard.png"
}
}
},
},
"code":1
}
}
}