jQuery $ .getJSON-如何解析flickr.photos.search REST API调用? [英] jQuery $.getJSON - How do I parse a flickr.photos.search REST API call?

查看:107
本文介绍了jQuery $ .getJSON-如何解析flickr.photos.search REST API调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试改编$ .getJSON Flickr示例:

Trying to adapt the $.getJSON Flickr example:

$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?",
    function(data){
    $.each(data.items, function(i,item){
        $("<img/>").attr("src", item.media.m).appendTo("#images");
        if ( i == 3 ) return false;
    });
});

从flickr.photos.search REST API方法读取,但是此调用的JSON响应不同.

to read from the flickr.photos.search REST API method, but the JSON response is different for this call.

这是我到目前为止所做的:

This is what I've done so far:

var url = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=YOURAPIKEYHERE&tags=yokota+air+base&safe_search=1&per_page=20";
var src;
$.getJSON(url + "&format=json&jsoncallback=?", function(data){
    $.each(data.photos, function(i,item){
        src = "http://farm"+ item.photo.farm +".static.flickr.com/"+ item.photo.server +"/"+ item.photo.id +"_"+ item.photo.secret +"_m.jpg";
        $("<img/>").attr("src", src).appendTo("#images");
        if ( i == 3 ) return false;
    });
});

我想我没有正确构建图像src.根据JSON响应,找不到有关如何构建图像src的任何文档. 您如何解析flickr.photos.search REST API调用?

I guess I'm not building the image src correctly. Couldn't find any documentation on how to build the image src, based on what the JSON response is. How do you parse a flickr.photos.search REST API call?

推荐答案

没关系,我明白了.对于那些感兴趣的人,它的解析方式如下:

Nevermind, I got it. For those that are interested, it's parsed like so:

var url = "http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=YOURAPIKEYHERE&tags=yokota+air+base&safe_search=1&per_page=20";
var src;
$.getJSON(url + "&format=json&jsoncallback=?", function(data){
    $.each(data.photos.photo, function(i,item){
        src = "http://farm"+ item.farm +".static.flickr.com/"+ item.server +"/"+ item.id +"_"+ item.secret +"_m.jpg";
        $("<img/>").attr("src", src).appendTo("#images");
        if ( i == 3 ) return false;
    });
});

请注意,.photo已移至$ .each方法签名.

Notice the .photo was moved to the $.each method signature.

这篇关于jQuery $ .getJSON-如何解析flickr.photos.search REST API调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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