Correct usage is:
for(var video in playlist){
document.write(video + " "+ playlist[video].VideoTitle +"<br>");
}
题
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
解决方案
Correct usage is:
for(var video in playlist){
document.write(video + " "+ playlist[video].VideoTitle +"<br>");
}
其他提示
This should work,
var playlist = JSON.parse('{"VideoID" : {"VideoTitle" : "the title of the video"} }');
document.write(playlist.VideoID.VideoTitle);