Google Feed Loader API忽略XML属性 [英] Google Feed Loader API ignoring XML attributes

查看:111
本文介绍了Google Feed Loader API忽略XML属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google的Feed加载程序在转换为JSON时似乎忽略了属性. 我正在使用jQuery通过AJAX抓取供稿. 可以在此处看到实际的RSS XML提要,并且AJAX调用的响应可以是在此处中看到.

Google's feed loader appears to be ignoring attributes when converting to JSON. I'm using jQuery to grab a feed via AJAX. The actual RSS XML feed can be seen here, and the response from the AJAX call can be seen here.

我需要访问<enclosure>标记的url属性,但两者均未出现在响应中.

I need to access the urlattribute of the <enclosure> tags, but neither appear in the response.

作为参考,我使用的代码是:

For reference, the code I am using is:

function getFeed(url) {
    url = 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' 
            + encodeURIComponent(url);
    $.ajax({
        type: 'GET',
        url: url,
        dataType: 'jsonp',
        cache: false,
        success: function(d) { alert(JSON.stringify(d); },
        error: function(s,x) { alert(x); }
    }); 
}

我不知道如何获取XML响应,因为更改dataType : 'xml'会导致HTTP错误.最好使用JSON.

I can't figure out how to get an XML response instead, as changing dataType : 'xml' causes an HTTP error. JSON is preferable.

有什么想法吗?

推荐答案

JSON响应中不包含'enclosure'标记,因此有两个选项可设置输出参数:

The 'enclosure' tag is not included in the JSON response, so you have two options setting the output argument:

您需要将输出设置为"XML": https://developers.google .com/feed/v1/jsondevguide#json_args

You need to set the output to 'XML': https://developers.google.com/feed/v1/jsondevguide#json_args

url = 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&output=xml&num=10&callback=?&q='+ encodeURIComponent(url); 

或使用混合格式: https://developers.google.com/feed/v1/devguide#resultMixed

url = 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&output=json_xml&num=10&callback=?&q='+ encodeURIComponent(url); 

您将获得JSON以及带有所有标记(包括附件"属性)的新xmlString属性

You´ll get the JSON plus a a new xmlString property with all the tags (including 'enclosure' attributes)

alert(d.responseData.xmlString);

在两种情况下,您都需要解析XML字符串并导航到所需的信息

In both cases you need to parse the XML string and navigate to the needed info

希望这会有所帮助

这篇关于Google Feed Loader API忽略XML属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆