jQuery, JSON, Flickr API

别来无恙 提交于 2019-12-03 21:11:27

Use

$.ajax({
    url: "http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&format=json&api_key=708f179518b2093d23f0aef284b565a4&photo_id=6115633659&jsoncallback=?",
    type: "GET",
    cache: true,
    dataType: 'jsonp',
    success: function(data) {

        var sizelist = data.sizes.size;
        for (var i = 0; i < sizelist.length; i++) {
            if (sizelist[i].label == 'Original') largeSRC = sizelist[i].source;
        }

        alert(largeSRC);

    }
});

Demo at http://jsfiddle.net/NGr23/

The problem is that size is an array. So you need to iterate over its elements to find the one with label of 'Original' ..

Try this one http://jsfiddle.net/genesis/TyDHK/5/

 $.ajax({
    url: "http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&format=json&api_key=708f179518b2093d23f0aef284b565a4&photo_id=6115633659&jsoncallback=?",
    type: "GET",
    cache: true,
    dataType: 'jsonp',
    success: function(data) {

        var largeSRC = data.sizes.size[6].width + ' ' + data.sizes.size[6].height ;

        alert(largeSRC);

    }
});

Try this.

var url = "http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&format=json&api_key=708f179518b2093d23f0aef284b565a4&photo_id=6115633659&jsoncallback=?";
var largeSRC = "";
$.getJSON(url, function(data) {
    $.each(data.sizes.size, function(i, datum) {
        $.each(datum, function(key, value) {
            if (key === "label" && value === "Original") {
                largeSRC = datum.source;
                alert(largeSRC);
            }
        });
    });
});

Demo: http://jsfiddle.net/naveen/PZNT6/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!