我正在努力解析来自XMLHttpRequest的响应。响应是JSON格式:解析来自XMLHttpRequest的响应
http://flickr.com/services/rest/?method=flickr.photos.search&api_key=75564008a468bf8a284dc94bbd176dd8&tags=paris&format=json
,以确保它确实进来这样我测试了它:
document.getElementById('info').innerHTML = this.responseText
返回我一个页面,写JSON格式数据的长线。可能有人帮我找出为了从即所有的标题
的列表响应中提取数据的下一步骤,我做了一些研究和碰到这个传来:
response = this.responseText ;
var doc = new DOMParser().parseFromString(response, "text/xml");
我需要什么,下一步该怎么做? (注:我希望这样做手工即不jQuery的或类似工具的帮助下)
基于以下部分以及Flickr page on that matter的建议[编辑]
,我已经试过如下:
request.onreadystatechange = function()
{
...
if (this.responseXML != null)
{
jsonFlickrApi(this.responseText) ;
function jsonFlickrApi(rsp){
for (var i=0; i<rsp.photos.photo.length; i++){
var blog = rsp.photos.photo[i];
var div = document.createElement('div');
var txt = document.createTextNode(photo.owner);
div.appendChild(txt);
//document.body.appendChild(div);
document.getElementById('info').innerHTML.appendChild(div);
}
...
}
这不会返回任何可见的东西。
[EDIT2]
进一步的故障诊断显示:
rsp = this.responseText ;
document.getElementById('info').innerHTML = rsp.stat ;
打印undefined
= function(d)...'d'做了什么或它从哪里来? – raoulbia 2011-03-19 18:51:36
非常感谢!你的代码片段就是我的救世主:) – raoulbia 2011-03-19 20:10:45
@all:感谢你的帮助!选择接受答案是一个困难的选择。我选择了在特定情况下具有最大实际价值的那个。再次感谢。 – raoulbia 2011-03-19 20:11:42