Here is my example data: http://api.setlist.fm/rest/0.1/setlist/4bf763f6.json
I'm just writing a node app that prints out the details of this page. What I'm concerned with are sets, set and song.
var sets = setlist.sets
res.write(JSON.stringify(sets)) // THIS SHOWS THE CORRECT DATA
var numSets = Object.keys(sets).length;
for(var i = 0; i < numSets; i++){
res.write("\nsets " + i);
var set = sets.set[i];
console.log(Object.getOwnPropertyNames(set))
var numSet = Object.keys(set).length;
res.write(JSON.stringify(set))
for(var j = 0; j < numSet; j++){
res.write("\nset " + (j+1) + " of " + numSet);
var song = set.song;
console.log(Object.getOwnPropertyNames(song))
numSong = Object.keys(song).length;
for(var k = 0; k < numSong; k++){
res.write("\n song " + j + "-" + k);
res.write("\n "+JSON.stringify(song[k]["@name"]));
}
}
}
what I get is:
set 1 of 1
song 0-0
"Lift Me Up"
song 0-1
"Hard to See"
song 0-2
"Never Enough"
song 0-3
"Got Your Six"
song 0-4
"Bad Company"
song 0-5
"Jekyll and Hyde"
song 0-6
"Drum Solo"
song 0-7
"Burn MF"
song 0-8
"Wrong Side of Heaven"
song 0-9
"Battle Born"
song 0-10
"Coming Down"
song 0-11
"Here to Die"
There are TWO song elements in set: (sorry no code block or it won't wrap)
{
"set": [{
"song": [{
"@name": "Lift Me Up"
}, {
"@name": "Hard to See"
}, {
"@name": "Never Enough"
}, {
"@name": "Got Your Six"
}, {
"@name": "Bad Company",
"cover": {
"@disambiguation": "British blues-rock supergroup",
"@mbid": "0053dbd9-bfbc-4e38-9f08-66a27d914c38",
"@name": "Bad Company",
"@sortName": "Bad Company",
"@tmid": "734487",
"url": "http://www.setlist.fm/setlists/bad-company-3bd6b8b0.html"
}
}, {
"@name": "Jekyll and Hyde"
}, {
"@name": "Drum Solo"
}, {
"@name": "Burn MF"
}, {
"@name": "Wrong Side of Heaven",
"info": "Acoustic"
}, {
"@name": "Battle Born",
"info": "Acoustic and Electric"
}, {
"@name": "Coming Down"
}, {
"@name": "Here to Die"
}]
}, {
"@encore": "1",
"song": [{
"@name": "Under and Over It"
}, {
"@name": "Burn It Down"
}, {
"@name": "The Bleeding"
}]
}]
}
In Swift I just make set a Dictionary and it works just fine. Javascript is not my forte. Why can't I get that second song element?