jQuery $.getJSON - How do I parse a flickr.photos.search REST API call?

后端 未结 4 977
借酒劲吻你
借酒劲吻你 2021-01-31 06:15

Trying to adapt the $.getJSON Flickr example:

$.getJSON(\"http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jso         


        
4条回答
  •  情书的邮戳
    2021-01-31 06:40

    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";
            $("").attr("src", src).appendTo("#images");
            if ( i == 3 ) return false;
        });
    });
    

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

提交回复
热议问题