jQuery json根本不起作用

时间:2013-08-27 13:07:34

标签: jquery json

我尝试从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自己尝试。

我该怎么做?

3 个答案:

答案 0 :(得分: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
    });
});

答案 1 :(得分:0)

尝试这样的事情

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

答案 2 :(得分:0)

您是否从查询中验证了网络响应?显然您获得的对象是一个数组,因此它将是:

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

相关问题