bjesua bjesua - 1 month ago 7
Ajax Question

access to multidimentional json

I´m using ajax to read a generated php json, i need to acces to this values.
does anyone have any idea .

$.ajax({
url: "jsonReturn.php",
type: "POST",
data: {
tipoFlujo: 2,
codigoInternoAviso: aviso
},
async: false,
statusCode: {
404: function () {
alert("Página no encontrada");
}
},
success: function (data) {
console.log(data);

}
});


the json generated is something like this.

{
"3": [{
"NU": "3",
"ESTAD": "0"
}],
"5": [{
"NU": "5",
"ESTAD": "RECHAZADO"
}],
"8": [{
"NU": "8",
"ESTAD": "0"
}]
}


so, what i need to know is how to access to each value on the ajax success .

thank you so much.

Answer

i want to answer this question.

i need to add the dataType: "json",

$.ajax({
        url: "jsonReturn.php",
        type: "POST",
        dataType: "json",
        data: {
           tipoFlujo: 2,
           ci: aviso
         },
         async: false,
         statusCode: {
         404: function () {
             alert("Página no encontrada");
         }
           },
         success: function (data) {            
         console.log(data[3][0]["NU"]);
         }
});

To acces to the values from data result i can acces like this

console.log(data[3][0]["NU"]);