azz*_*azz 2 xml rss jquery json google-feed-api
转换为JSON时,Google的Feed加载程序似乎忽略了属性.我正在使用jQuery通过AJAX获取feed.实际的RSS XML提要可以看到这里,并从AJAX调用的响应可以看出这里.
我需要访问标签的url属性<enclosure>,但都不会出现在响应中.
作为参考,我使用的代码是:
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); }
});
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何获得XML响应,因为更改dataType : 'xml'会导致HTTP错误.JSON是首选.
有任何想法吗?
'enclosure'标记未包含在JSON响应中,因此您有两个选项来设置输出参数:
您需要将输出设置为"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);
Run Code Online (Sandbox Code Playgroud)
或使用混合格式: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);
Run Code Online (Sandbox Code Playgroud)
您将获得JSON以及包含所有标记的新xmlString属性(包括"enclosure"属性)
alert(d.responseData.xmlString);
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,您都需要解析XML字符串并导航到所需的信息
希望这可以帮助
| 归档时间: |
|
| 查看次数: |
3422 次 |
| 最近记录: |