我需要解析enclosure标记以获取url图像。我假设我应该使用json + xml代码获取MIXED OUTPUT,但是当我尝试解析它时,我从enclousure标签中得到一个未定义的值。就像我在这篇文章中看到的那样,我这样做> Google Feed Loader API ignoring XML attributes< 。此外,我试图手动编写网址的MIXED格式,但它不起作用。有我的整个代码。我怎么知道我得到混合的json输出?
var feeds = [];
var entryImageUrl = [];
angular.module('starter.controllers', ['ngResource','ngLocale'])
.factory('FeedLoader', function ($resource) {
return $resource('http://ajax.googleapis.com/ajax/services/feed/load', {}, {
fetch: { method: 'JSONP', params: {v: '1.0', callback: 'JSON_CALLBACK', output: 'json_xml'} }
});
})
.service('FeedList', function ($rootScope, FeedLoader) {
this.get = function() {
var feedSources = [
{title: 'Heraldo De Barbate', url: 'http://www.heraldodebarbate.es/rss/last'},
];
if (feeds.length === 0) {
for (var i=0; i<feedSources.length; i++) {
FeedLoader.fetch({q: feedSources[i].url, num: 10}, {}, function (data) {
var feed = data.responseData.feed;
**var entryImageUrl = feed.xmlNode.getElementsByTagName("enclosure")[i].getAttribute("url");**
feeds.push(feed);
});
}
}
return feeds;
};
})
.controller('FeedCtrl', function ($scope, FeedList,$timeout) {
$scope.update = function(){
$scope.feeds = FeedList.get();
$scope.$on('FeedList', function (event, data) {
$scope.feeds = data;
// $scope.entryImageUrl
console.log(feeds);
});
$timeout(function() {
$scope.$broadcast('scroll.refreshComplete');
}, 500);
}
})
答案 0 :(得分:0)
我怎么知道我得到混合的json输出?
在JSON中使用标签测试:
function testMe(node)
{
return /</.test(JSON.stringify(node) )
}
然后在Feed上运行它:
var mixed_format = testMe(feed);
并调用另一个解析数据的函数:
if (mixed_format)
{
mixed_parser(feed)
}
else
{
json_parser(feed)
}