Get the labels of a JSON

1

I'm doing a API that receives a JSON and I need to get which tags are inside that JSON .

This is an example of JSON :

[{
    "Notification": [{
        "Channel": 4,
        "Type": 1,
        "Means": [{
            "Number": 88888888,
            "Code": 506
        }],
        "Contents": {
            "Message": "This is a message",
            "Audio": "URL"
        }
    }]
}]

In this case I need to get the Contents tags, that is, Message and Audio .

I tried to work with a code like this:

f.Notification.forEach(e =>{
    console.log(e.Contents);
})

But that shows me everything and I just need the label ... Any ideas?

    
asked by java005 11.09.2018 в 23:19
source

2 answers

1

And what if you change your code a bit and leave it this way:

f.Notification.forEach(e =>{
    for(var etiqueta in e.Contents)
        console.log(etiqueta);
})
    
answered by 11.09.2018 / 23:28
source
1

You can try this

f.Notification.forEach(e => {
      console.log(Object.keys(e.Contents));
});
    
answered by 12.09.2018 в 07:35