gpt4 book ai didi

jQuery、JSON、Flickr API

转载 作者:行者123 更新时间:2023-12-01 02:47:49 25 4
gpt4 key购买 nike

    $.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.Original;

alert(largeSRC);

}
});

所以,是的,基本上,我不知道如何...我什至不知道如何术语。我正在尝试获取原始大小的 URL。 http://www.flickr.com/services/api/explore/flickr.photos.getSizes

jsonFlickrApi({ "sizes": { "canblog": 0, "canprint": 0, "candownload": 1, 
"size": [
{ "label": "Square", "width": 75, "height": 75, "source": "http:\/\/farm7.static.flickr.com\/6068\/6115633659_500f8bbd74_s.jpg", "url": "http:\/\/www.flickr.com\/photos\/b34u_h4r13y_n47h4n_7h0m45\/6115633659\/sizes\/sq\/", "media": "photo" },
{ "label": "Thumbnail", "width": 100, "height": 66, "source": "http:\/\/farm7.static.flickr.com\/6068\/6115633659_500f8bbd74_t.jpg", "url": "http:\/\/www.flickr.com\/photos\/b34u_h4r13y_n47h4n_7h0m45\/6115633659\/sizes\/t\/", "media": "photo" },
{ "label": "Small", "width": "240", "height": "159", "source": "http:\/\/farm7.static.flickr.com\/6068\/6115633659_500f8bbd74_m.jpg", "url": "http:\/\/www.flickr.com\/photos\/b34u_h4r13y_n47h4n_7h0m45\/6115633659\/sizes\/s\/", "media": "photo" },
{ "label": "Medium", "width": "500", "height": "331", "source": "http:\/\/farm7.static.flickr.com\/6068\/6115633659_500f8bbd74.jpg", "url": "http:\/\/www.flickr.com\/photos\/b34u_h4r13y_n47h4n_7h0m45\/6115633659\/sizes\/m\/", "media": "photo" },
{ "label": "Medium 640", "width": "640", "height": "424", "source": "http:\/\/farm7.static.flickr.com\/6068\/6115633659_500f8bbd74_z.jpg", "url": "http:\/\/www.flickr.com\/photos\/b34u_h4r13y_n47h4n_7h0m45\/6115633659\/sizes\/z\/", "media": "photo" },
{ "label": "Large", "width": "1024", "height": "678", "source": "http:\/\/farm7.static.flickr.com\/6068\/6115633659_500f8bbd74_b.jpg", "url": "http:\/\/www.flickr.com\/photos\/b34u_h4r13y_n47h4n_7h0m45\/6115633659\/sizes\/l\/", "media": "photo" },
{ "label": "Original", "width": "1440", "height": "954", "source": "http:\/\/farm7.static.flickr.com\/6068\/6115633659_cdaca906e1_o.jpg", "url": "http:\/\/www.flickr.com\/photos\/b34u_h4r13y_n47h4n_7h0m45\/6115633659\/sizes\/o\/", "media": "photo" }
] }, "stat": "ok" })

请帮助我逃离这个可怕的猜谜游戏。

谢谢。

最佳答案

使用

$.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);

}
});

演示地址:http://jsfiddle.net/NGr23/

问题是 size 是一个数组。因此,您需要迭代其元素以找到 label 为“Original”的元素..

关于jQuery、JSON、Flickr API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7311538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com