【发布时间】:2011-03-28 17:05:48
【问题描述】:
我确信这是一个简单的问题,所以我提前道歉,甚至提出这个问题。在下面的代码中,我使用 jGFeed 插件将 RSS 提要转换为 JSON。在这个 JSON 中,我需要访问嵌套数组中嵌套数层的 URL 节点。现在,我可以使用 "console.log("feeds.entries[i]")" 在父级别获取每个对象的一些属性(即,“标题”、“内容”等)。我只是不知道如何深入到嵌套数组中。
这是我的代码:
$(document).ready(function() {
$.jGFeed('http://feeds.feedburner.com/solidverbal/app', function(feeds){
// Check for errors
if(!feeds){
// there was an error
return false;
}
var sAnchors = "<ul>";
//var wantedFeed = "";
for(var i=0; i<feeds.entries.length; i++){
console.log(feeds.entries[i]);
var sAnchors = sAnchors + "<li><a href=\"#link\" id=\"title_" + i + "\" class=\"giveFeeds\">" + feeds.entries[i].title + "</a></li>";
}
sAnchors = sAnchors + '</ul>';
//Append the <a>.
$('#titles').append(sAnchors);
//When the user clicks on the giveFeeds link....
$('.giveFeeds').live('click', function(e) {
//Get the feed number
var tmpId = $(e.target).attr("id");
//Returns the value after the '_' char and make sure it returns de number.
var id = parseInt(tmpId.split("_")[1]);
//Use the id value to get the desired feed
var wantedFeed = feeds.entries[id].content;
//Then do whatever you want with that entry
$("#content").html(wantedFeed);
});
}, 20);
});
以下是显示在 Chrome 控制台中的 JSON 结构示例:
Object
author: "Test"
categories: Array[10]
content: "<p></p><p>Test Content"
contentSnippet: "Test Content Snippet"
link: "http://www.solidverbal.com/2011/03/24/charles-robinson-324/"
mediaGroups: Array[1]
0: Object
contents: Array[1]
0: Object
fileSize: "12796261"
type: "audio/mpeg"
url: "http://www.testurl/test.mp3"
任何帮助将不胜感激。我认为这是一个嵌套的 for 循环或其他东西,但无论出于何种原因,我都无法理解。
提前致谢!
【问题讨论】:
标签: jquery json jquery-plugins rss multidimensional-array