Reputation: 1495
var playlist = JSON.parse('{"VideoID" : {"VideoTitle" : "the title of the video"} }');
for(var video in playlist){
document.write(video + " "+ video.title +"<br>");
}
the output is : VideoID undefined
I want to the out put to be : VideoID the title of the video
Upvotes: 0
Views: 76
Reputation: 29015
This should work,
var playlist = JSON.parse('{"VideoID" : {"VideoTitle" : "the title of the video"} }');
document.write(playlist.VideoID.VideoTitle);
Upvotes: 0
Reputation: 16068
Correct usage is:
for(var video in playlist){
document.write(video + " "+ playlist[video].VideoTitle +"<br>");
}
Upvotes: 2