I have one extremely complex json object, I’m needing to write all the properties and keys out as they are. I’ve got the concept of it just can’t get the execution.
Needing to keep recalling the function if the object has a object and so on. I’m hitting snags though, some of the keys aren’t being outputted, some of the values are being broken up as
0:h 1:t 2:t 3:p 4: 5:/ 6:/ etc....
name:Travel
scheme:
label:
I assume there’s a little error somewhere in my code that needs to be changed.
ObjectValues = function(obj){
for(var j in obj){
if(typeof(obj[j]) == "object"){
for(var k in obj[j]){
ObjectValues(obj[j][k]);
}
} else {
console.log(j + ":" + obj[j]);
}
}
_
{
"title": "Norway Tourism: Wildlife and Nature",
"author": "",
"categories": [
{
"name": "Travel",
"scheme": "",
"label": ""
}
],
"countries": [
],
"content": [
{
"thumbnails": [
{
"audioChannels": 0,
"audioSampleRate": 0,
"bitrate": 0,
"checksums": {
"md5": "7089E4E044069AE7702DEC686"
}
}
]
}
]
}
should work even for JSON values that are not objects. It will work for
which would not be handled by the original and it will not iterate over characters in a top-level string if you do
ObjectValues("http://...").