Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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
Jquery 未定义的读取JSON_Jquery_Json - Fatal编程技术网

Jquery 未定义的读取JSON

Jquery 未定义的读取JSON,jquery,json,Jquery,Json,我用这段代码来获取一个json对象,这很有效 $.getJSON("http://api.songkick.com/api/3.0/artists/" + artist_id + "/calendar.json?apikey=Key&jsoncallback=?", function callback(json) { $.each(json["resultsPage"], function (i, entry) { alert(entry.totalEntrie

我用这段代码来获取一个json对象,这很有效

$.getJSON("http://api.songkick.com/api/3.0/artists/" + artist_id + "/calendar.json?apikey=Key&jsoncallback=?", function callback(json) {

    $.each(json["resultsPage"], function (i, entry) {
        alert(entry.totalEntries);
    });
});
当我执行代码时,如果没有关于艺术家的数据,我会得到:

?({"resultsPage":{"results":{},"totalEntries":0,"perPage":50,"page":1,"status":"ok"}})
我想要的是得到totalEntries的值,以验证是否有一些数据,但我一直没有定义。我正在使用警报来显示值

问题可能是什么,或者是获取totalEntries或验证查询是否存在问题的更好方法

一个好的(当发现某事时):


您正在迭代“resultsPage”的字段,而不是“resultsPage”本身。我想你的意思是:

alert(json.resultsPage.totalEntries); // Without the "each", you don't need it
自己测试,将代码更改为

$.each(json["resultsPage"], function (i, entry) {
    alert([i, entry]);
});
它将发出警报(无特定顺序):


删除了我的评论,因为它是垃圾。刚才还记得,这实际上可能是JSONP
$.each(json["resultsPage"], function (i, entry) {
    alert([i, entry]);
});
results, [object Object]
totalEntries, 0
perPage, 50
page, 1
status, ok