如何通过json检索flickr图像的图像描述

时间:2011-02-21 14:33:00

标签: jquery json jsonp flickr

我正在使用以下json url从flickr

中检索图像
http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=***&photoset_id=72157625776815845&extras=original_format&format=json&jsoncallback=?

响应

jsonFlickrApi({"photoset":{"id":"72157625776815845", "primary":"5386650651", "owner":"58668842@N05", "ownername":"mohanramphp", "photo":[{"id":"5386650651", "secret":"fcfc73c14f", "server":"5214", "farm":6, "title":"image5", "isprimary":"1"}, {"id":"5387254114", "secret":"76e63d565e", "server":"5215", "farm":6, "title":"image4", "isprimary":"0"}, {"id":"5386650273", "secret":"2f0d19575a", "server":"5214", "farm":6, "title":"image3", "isprimary":"0"}, {"id":"5387253836", "secret":"66f2ec20a7", "server":"5214", "farm":6, "title":"image2", "isprimary":"0"}, {"id":"5387253676", "secret":"f159c8d52a", "server":"5212", "farm":6, "title":"image1", "isprimary":"0"}], "page":1, "per_page":500, "perpage":500, "pages":1, "total":"5"}, "stat":"ok"})

我还需要通过json获取图像描述。我不知道该怎么做。我尝试了flickr提供的所有json url。如果有任何flickr json来检索我自己的图像描述。

2 个答案:

答案 0 :(得分:0)

您可以查看working sample

答案 1 :(得分:0)

获得标题需要做的是:

titles=[]
ids=[]
photoset.each do |photo|
titles<<photo.title
ids<<photo.id
end

或在jQuery中:

    var items = [];
    $.getJSON(url, function(data) {
        if (data.photoset==null)
        {
        alert("you didnt freakin do it right!!")
        }
        else
        {
        $.each(data.photoset.photo, function(){

        items.push('<li id="' + this['id'] + '">' + this['title']</li>');
          });

          $('<ul/>', {
            'class': 'my-new-list',
            html: items.join('')
          }).appendTo('body');

});

然后对于说明,请使用http://www.flickr.com/services/api/flickr.photos.getInfo.html中列出的流程 photos.getInfo(一个额外的API调用)并从每个图片中检索描述