我想显示网页上播放的最后10首歌曲。这是我正在使用的代码,但我无法从json文件中检索和显示所请求的信息。 https://jsfiddle.net/Heropiggy95/6qkv7z3b/有人可以指出错误或演示一个有效的例子吗?谢谢。
$(document).ready(function() {
$.getJSON("http://apps.radioactive.sg/lastsongsplayed.php?stationId=995fm&callback=myfunction", function(data) {
var html = ''; // declare the variable that will be used to store the information
$.each(data.myfunction, function(i, item) {
{
html += 'Song: ' + item.song.track + ', Artist: ' + item.song.artist + ', Time: ' + item.playedtime + '';
} //
}); //
$('.nowplaying').append(html); // print the information to the document with a span class of 'nowplaying' and use the jQuery append method to insert the information.
}); // close JSON call
}); // close document ready function
答案 0 :(得分:0)
尝试像这样使用JSON.parse
$(document).ready(function() {
$.getJSON("http://apps.radioactive.sg/lastsongsplayed.php?stationId=995fm", function(data) {
var html = ''; // declare the variable that will be used to store the information
var parsedData = JSON.parse(data);
$.each(parsedData, function(i, item) {
{
html += 'Song: ' + item.song.track + ', Artist: ' + item.song.artist + ', Time: ' + item.playedtime + '';
} //
}); //
$('.nowplaying').append(html); // print the information to the document with a span class of 'nowplaying' and use the jQuery append method to insert the information.
}); // close JSON call
}); // close document ready function