需要帮助解析json网页上的数据

问题描述:

我想显示网页上播放的最后10首歌曲。这里是我正在使用的代码,但我无法从json文件中检索和显示请求的信息。 https://jsfiddle.net/Heropiggy95/6qkv7z3b/有人可以指出错误或展示一个工作示例吗?谢谢。需要帮助解析json网页上的数据

$(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

'它不是working'可能是你能提供的最糟糕的信息。请给一些更多的细节。 – C4u

尝试使用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 
+0

这是我一直在努力的代码,但我似乎无法生成输出。 https://jsfiddle.net/Heropiggy95/6qkv7z3b/我不知道我应该采取什么措施来纠正问题。你能告诉我如何解决这个页面?谢谢。 – HeroPiggy95

+0

您是否尝试在localhost或任何其他域上运行此代码。,我试图在本地运行它并给出: 否请求的资源上存在“Access-Control-Allow-Origin”标头。 Origin'http://fiddle.jshell.net'因此不被允许访问。 您需要在您的服务器上处理此问题,以允许您的域发送ajax请求。 –

+0

我想在本地主机上运行它。我做了我的研究,这表明'Access-Control-Allow-Origin'可以通过在jsonp中使用ajax来绕过。 http://stackoverflow.com/questions/5943630/basic-example-of-using-ajax-with-jsonp是否有可能使用此方法从服务器获取信息? – HeroPiggy95