Javascript 如何使用GoogleFeedAPI访问提要中的第一个图像?
我正在使用GoogleFeedAPI将提要解析为HTML。我试图从JSON的内容体访问第一个图像。这是我现在的剧本:Javascript 如何使用GoogleFeedAPI访问提要中的第一个图像?,javascript,json,google-feed-api,Javascript,Json,Google Feed Api,我正在使用GoogleFeedAPI将提要解析为HTML。我试图从JSON的内容体访问第一个图像。这是我现在的剧本: function parseRSS(url, container) { $.ajax({ url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponen
function parseRSS(url, container) {
$.ajax({
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent(url),
dataType: 'json',
success: function(data) {
console.log(data.responseData.feed);
// $(container).html('<h2>'+capitaliseFirstLetter(data.responseData.feed.title)+'</h2>');
$.each(data.responseData.feed.entries, function(key, value) {
var images = $(value.content).find('img').map(function(){
return $(this).attr('src')
}).get();
$(container).append('<article><h3><a href="'+ value.link +'" target="_blank"> '+ value.title +' </a></h3>'+ ( images.length == 0 ? '' : '<img src="'+ images[0] + '"/>' )+'<p>'+ value.contentSnippet +'</p></article>');
});
}
});
}
function capitaliseFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
它可以很好地获取第二个图像,但不能获取第一个图像。有什么建议吗?console.log$value.content.find'img'[0].src?显示第一个映像的src?@dandavis控制台显示它正在加载第二个映像,而不是第一个映像。我的控制台logdata.responseData.feed在content:body中显示正确的第一个图像URL。