Browsing List List in Jquery (JSON)

0

Well, I have a JSON, which will be returned by an ajax, with the following structure:

{
"ExtensionData": {},
"CodCli": null,
"Codigo": 0,
"Data": "/Date(-62135589600000)/",
"Detalhes": {
    "ExtensionData": {},
    "Carregamento": "001 - JUNDIAI             ",
    "Documento": null,
    "Origem": "001 - JUNDIAI             ",
    "listVolumes": [
        {
            "ExtensionData": {},
            "CodCli": "EJ061474510015380004575480010001009200101",
            "Codigo": "0000005459",
            "SeqVol": 1
        },
        {
            "ExtensionData": {},
            "CodCli": "EJ061474510015380004575480010002009200101",
            "Codigo": "0000005460",
            "SeqVol": 2
        },
        {
            "ExtensionData": {},
            "CodCli": "EJ061474510015380004575480010003009200101",
            "Codigo": "0000005461",
            "SeqVol": 3
        }
    ]
},
"NomeCli": null,
"NotaFiscal": null,
"Origem": null,
"Viagem": null,
"strData": null
}

I want to access elements that are within listVolumes , that is, pass the path: "Raiz" -> Detalhes -> listVolumes .

    
asked by anonymous 24.04.2015 / 16:20

2 answers

2

You can use $ .each

$.each(Seu_array_json.Detalhes.listVolumes,function(i, value){
    console.log(value); // value = cada item da listVolumes
});
    
24.04.2015 / 16:25
3

I do not know what you've tried, but it's very simple:

$.getJSON(url_do_seu_json, function(dados) {
    var volumes = dados.detalhes.listVolumes;
    volumes.forEach(function(item) {
        // pegue aqui os dados do item, por exemplo:
        console.log(item.CodCli);
    });
});
    
24.04.2015 / 16:25