我正在使用 Java脚本
处理Windows 8应用我的RSS源很少,比如:
http://dmadmin.dailymirror.lk/index.php?option=com_ninjarsssyndicator&feed_id=16&format=raw
http://dmadmin.dailymirror.lk/index.php?option=com_ninjarsssyndicator&feed_id=17&format=raw
以下函数获取每个rss feed并转换为JSON对象。但我想要做的是将所有rss提供给一个JSON对象。 (有两个rss feed。所以在函数调用之后它给了我两个独立的JSON对象。但是我想要一个对象)
for (x = 0; x < listOfFeed.length; x++) {
//loop x start
feedburnerUrl = listOfFeed[x].url,
feedUrl = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&output=json&num=999&q=" + encodeURIComponent(feedburnerUrl);
WinJS.xhr({
url: feedUrl,
responseType: "rss/json"
}).done(function complete(result) { //result = [object XMLHttpRequest] for the requested URLs
var jsonData = JSON.parse(result.response); //jsonData = [object Object] create Object
var entries = jsonData.responseData.feed.entries; //entries = [object object][object object][object object]......
entries.forEach(function (entry) { // process the entries...
console.log('{"title" :"' + entry.title + '","Date":"' + entry.publishedDate + '"},');
});
});
} //loop x finish
}
感谢您的帮助......
答案 0 :(得分:0)
您可以使用Array.concat()
加入条目数组。您还可以跟踪未完成请求的数量,然后在条目达到0时处理这些条目。例如:
var allEntries = [];
var pendingRequestCount = listOfFeed.length;
var onRequestFinished = function() {
pendingRequestCount--;
if (pendingRequestCount === 0) {
allEntries.forEach(function (entry) { // process the entries...
console.log('{"title" :"' + entry.title + '","Date":"' + entry.publishedDate + '"},');
});
}
};
for (x = 0; x < listOfFeed.length; x++) {
... // Same as before
}).done(function complete(result) {
var jsonData = JSON.parse(result.response);
var entries = jsonData.responseData.feed.entries;
allEntries = allEntries.concat(entries);
onRequestFinished();
});
} //loop x finish
您还应该处理失败的请求并调用onRequestFinished函数。