Browse List in Jquery (JSON)

Asked

Viewed 746 times

0

Guys, 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 the elements inside listVolumes, that is, to pass by the way: "Raiz" -> Detalhes -> listVolumes.

2 answers

3

I don’t 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);
    });
});

2


You can use the $.each

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.