Javascript 使用Last.fm API获取图像

Javascript 使用Last.fm API获取图像,javascript,api,last.fm,Javascript,Api,Last.fm,我已经可以从我的Spotify帐户中获取上次播放的曲目和艺术家。代码: $.getJSON("http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&user=xxxxxx&api_key=xxxxxxxxx&limit=2&nowplaying=false&format=json&callback=?", function(data) { var html

我已经可以从我的Spotify帐户中获取上次播放的曲目和艺术家。代码:

    $.getJSON("http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&user=xxxxxx&api_key=xxxxxxxxx&limit=2&nowplaying=false&format=json&callback=?", function(data) {
        var html = '';
        var counter = 1;
        $.each(data.recenttracks.track, function(i, item) {
            if(counter == 1) {
            html += '<span>' + item.name + '<br /> ' + item.artist['#text'] + '</span>' + item.image;
            }
            counter++
        });

        $('.listening-to').append(html);

    });

您发出的API请求(用户最近的曲目)的响应中可能没有包含相册图像。或者,如果是,那么您试图访问错误的JSON属性。尝试双重检查原始JSON响应,查看相册图像URI是否在其中。如果不是,您将不得不单独调用API以获取更详细的唱片集信息。

使用
item.image[3]['#text']
而不是
item.image

不要投票也不要回答!
undefined