Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 带JSON数组值问题的Petfinder ajax请求_Javascript_Jquery_Json_Ajax - Fatal编程技术网

Javascript 带JSON数组值问题的Petfinder ajax请求

Javascript 带JSON数组值问题的Petfinder ajax请求,javascript,jquery,json,ajax,Javascript,Jquery,Json,Ajax,$(文档).ready(函数(){ var url='1〕http://api.petfinder.com/shelter.getPets?key=99392cbf55ee6b2f9b97ed375eca907d&id=WI22&status=A&output=full&format=json'; $.ajax({ 键入:“GET”, 数据:{}, url:url+'&回调=?', 数据类型:“json”, 跨域:是的, 成功:函数(数据){ var-petfinder=data.petfind

$(文档).ready(函数(){
var url='1〕http://api.petfinder.com/shelter.getPets?key=99392cbf55ee6b2f9b97ed375eca907d&id=WI22&status=A&output=full&format=json';
$.ajax({
键入:“GET”,
数据:{},
url:url+'&回调=?',
数据类型:“json”,
跨域:是的,
成功:函数(数据){
var-petfinder=data.petfinder;
console.log(petfinder.pets.pet[0].media.photos.photo['1','t','x']);
}
})

})
如果您想要第一只宠物的第一张照片,请尝试以下方法:

$(函数(){
var url='//api.petfinder.com/horder.getPets?key=99392cbf55ee6b2f9b97ed375eca907d&id=WI22&status=A&output=full&format=json';
$.ajax({
url:url,
数据类型:“jsonp”,
跨域:对
})
.完成(功能(数据){
console.log(
数据
petfinder先生
.宠物
.pet[0]
媒体
.照片
.照片[0]['$t']
);
});
});

是的,那些带有逗号分隔值的方括号不是访问javascript对象属性的有效方法,您希望该行做什么?我只想检索JSON字符串中第一个宠物(如图所示)的第一个图像。但是我不知道如何格式化行。
console.log(petfinder.pets.pet[0].media.photos.photo[0]['$t'])应输出url。这些奇怪的键名似乎是因为它们更习惯于服务XML文档,@对应于属性,$t对应于元素的文本。谢谢!这成功了@马修沃克总是受欢迎的。顺便说一句,我更新了所有3种可能性的答案。看看吧:)