Html 需要帮助解析网页上的json数据吗
我想在网页上显示最近播放的10首歌曲。下面是我正在使用的代码,但我无法从json文件中检索和显示请求的信息。有人能指出错误或演示一个工作示例吗?多谢各位Html 需要帮助解析网页上的json数据吗,html,json,Html,Json,我想在网页上显示最近播放的10首歌曲。下面是我正在使用的代码,但我无法从json文件中检索和显示请求的信息。有人能指出错误或演示一个工作示例吗?多谢各位 $(document).ready(function() { $.getJSON("http://apps.radioactive.sg/lastsongsplayed.php?stationId=995fm&callback=myfunction", function(data) { var html = ''; // d
$(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
试着像这样使用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
它不起作用
可能是你能提供的最糟糕的信息。请提供更多细节。这是我一直在编写的代码,但我似乎无法生成输出。我不知道应该采取什么措施来纠正这个问题。你能告诉我如何解决这一页的问题吗?谢谢。您是否尝试在本地主机或任何其他域上运行此代码。我尝试在本地运行此代码&它给出:请求的资源上不存在“Access Control Allow Origin”头。因此,不允许访问源“”。您需要在服务器上处理此问题,以允许您的域发送ajax请求。我正在尝试在localhost上运行它。我做了研究,这表明通过使用ajax和jsonp可以绕过“访问控制允许源代码”。是否可以使用此方法从服务器获取信息?