-1

我尝试从 php 中获取我所有的 json 对象,但似乎不起作用,我无法从中获取任何数据。

JSON:

  [{"courtid":"4","bookingid":"22673","centername":"Copenhagen","time":"8:9","date":"27-8-2013"},{"courtid":"3","bookingid":"22702","centername":"Copenhagen","time":"17:18","date":"27-8-2013"},{"courtid":"4","bookingid":"26422","centername":"Copenhagen","time":"7:9","date":"31-12-2013"},{"courtid":"5","bookingid":"26423","centername":"Copenhagen","time":"7:9","date":"31-12-2013"},{"courtid":"13","bookingid":"26424","centername":"Copenhagen","time":"7:9","date":"31-12-2013"}]

我的 jQuery ajax:

$.getJSON("http://f??????dboldfabrikken.dk/api/index.php?module=getAvailableGames",function(msg){
$.each(msg.courtid,function(index,item){
    alert(index + "..."+item);
});
});

代替 ??????带o自己试试。

我需要做什么?

4

3 回答 3

0

消息是一个数组,因此遍历数组以访问数组中项目的各个属性

$.getJSON("http://f??????dboldfabrikken.dk/api/index.php?module=getAvailableGames", function (msgs) {
    $.each(msgs, function (index, item) {
        alert(index + "..." + JSON.stringify(item));// here you can access item.courtid
    });
});
于 2013-08-27T13:11:16.357 回答
0

尝试这样的事情

    $.getJSON("http://f??????dboldfabrikken.dk/api/index.php?module=getAvailableGames",function(msg){
        $.each(msg,function(index,item){
            alert(index + "..."+item.courtid);
    });
于 2013-08-27T13:11:32.903 回答
0

您是否从您的查询中验证了您的网络响应?

显然你得到的对象是一个数组,所以它是:

$.each(msg, function(index, item))

ETC ...

于 2013-08-27T13:12:08.600 回答