我正在尝试data.artist.image
显示数组中的 url,以便稍后将其放入图像标签中。我不断在控制台中获取 [object][object]。为什么data.artist.image[0]
不给我数组中的第一项(小图像的 url)这是对象和代码:
Object {artist: Object}
artist: Object
bandmembers: Object
bio: Object
image: Array[5]
mbid: "0acae232-d31a-4211-b6d0-6af1b6350274"
name: "Thursday"
ontour: "0"
similar: Object
stats: Object
streamable: "1"
tags: Object
url: "http://www.last.fm/music/Thursday"
代码:所有 ajax 工作。我只是没有对阵列做正确的事情。
$.ajax({
dataType: "json",
url: "http://ws.audioscrobbler.com/2.0/?method=artist.getInfo&artist=Thursday&api_key=0bd6c5780da878f5bb51393e84329809&format=json&callback=?",
//data: (optional) and not used here
success: function(data){
console.log(data);
var html = "";
//var artist = data.artist;
html =
'<p>' + data.artist.image[0] + '</p>' +
'<p>' + data.artist.name + '</p>' +
'<p>' + data.artist.bio.content + '</p>';
$("#content").append(html);
},
complete: function(){
console.log("call is complete!");
},
error: function(){
console.log("something went wrong!");
}
});