javascript - Can I convert many rss feeds to single JSON file? -
i working windows 8 app using java script
i have few rss feeds, like:
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
following function each rss feed , convert json object..but want rss feed 1 json object. (there 2 rss feeds. after function call gave me 2 separate json objects. want 1 object)
(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] 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 entries... console.log('{"title" :"' + entry.title + '","date":"' + entry.publisheddate + '"},'); }); }); } //loop x finish }
- listoffeed = array of rss url.
- entries = each object in full json object (there 25 items inside 1 url).
- jsondata = json format of each url. got two.but want 1 json object these 2 urls.
thank help...
you can use array.concat()
join entries arrays. can track number of outstanding requests , process entries when reaches 0. like:
var allentries = []; var pendingrequestcount = listoffeed.length; var onrequestfinished = function() { pendingrequestcount--; if (pendingrequestcount === 0) { allentries.foreach(function (entry) { // process entries... console.log('{"title" :"' + entry.title + '","date":"' + entry.publisheddate + '"},'); }); } }; (x = 0; x < listoffeed.length; x++) { ... // same 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
you should handle failed requests , call onrequestfinished function well.
Comments
Post a Comment