var myData = {
"result": "success",
"theBox": {
"Brands": [{
"lastPublishTime": null,
"id": "e054e3d5-143c-4eab-9fc2-7740edce7d09",
"lastUpdateTime": "09:42 Sun Apr 27 2014 BST",
"name": "Brand A"
}, {
"lastPublishTime": "09:42 Tue Apr 29 2014 BST",
"id": "402f3c42-3d8d-45d6-8c50-c5d1b5025c23",
"lastUpdateTime": "09:42 Sun Apr 27 2014 BST",
"name": "Brand B"
}],
"Products": [{
"lastPublishTime": null,
"id": "db35610c-3148-4b89-856c-66f907206037",
"lastUpdateTime": "09:42 Sun Apr 27 2014 BST",
"name": "Product 1"
}],
"OtherStuff": []
}
}
var theTabsNames = (Object.getOwnPropertyNames(data.sandbox));
var arrayLength = theTabsNames.length;
for (var i = 0; i < arrayLength; i++) {
if (theTabsNames[i] != null) {
//var tabNumber = [i] + 1;
//console.log("Number:" +tabNumber);
var theTabName = theTabsNames[i];
var voiceSession = data.sandbox.theTabName;
//console.log("AAA" +voiceSession);
console.log("Name :" + voiceSession);
// var voiceSession = theTabsName[i];
var arrayLengthL = theTabName.length;
for (var j = 0; j < arrayLengthL; j++) {
if (data.sandbox.theTabName[j] != undefined) {
console.log("Name :" + data.sandbox.Brands[j].name);
console.log("lastUpdateTime :" + data.sandbox.Brands[j].lastUpdateTime);
console.log("lastPublishTime :" + data.sandbox.Brands[j].lastPublishTime);
console.log("Id :" + data.sandbox.Brands[j].id);
}
}
//Do something
}
}
I have no problem outputting this JSON but my issue is that values such as Brands, Products & OtherStuff might not be the same.
How do I find the names of the Objects then use them here? I can output the actual values but then they don't work when I try to use them to find the nodes.
console.log("Name :" +data.sandbox.Brands[j].name);