0

我的 php 文件是这样做的:

<?php include('connection.inc.php'); ?>
<?php header("Content-type: application/json"); ?>
<?php

    $sth = mysql_query("select * from ios_appointments a join ios_worker w join ios_partners p where a.workerid_fk = w.workerid and w.partnerid_fk =  p.partnerid and p.code = 'DEMO6003'");
    $rows = array();
    while($r = mysql_fetch_assoc($sth)) {
        $rows[] = $r;
    }
    print json_encode($rows);

?>

它返回这个 JSON 输出:

[{"appointmentId":"25","start":"2013-01-07 14:45:00","end":"2013-01-07 15:45:00","workerid_fk":"1","userid_fk":"22","isActive":null,"workerid":"1","prename":"Sarah","lastname":"Gonzalez","avatar":"megan.jpg","lineup":"Herren\/Damen","languages":"DE EN","partnerid_fk":"6","partnerid":"6","code":"DEMO6003","partnerName":"Demo Partner","street":"bla 1","zipCode":"bla","city":"bla","workers":"n\/a","email":"test@test.com","phone":"+41414441111","slogan":"Demo Partner zum Erkunden der App"},{"appointmentId":"26","start":"2013-01-10 11:15:00","end":"2013-01-10 12:15:00","workerid_fk":"1","userid_fk":"22","isActive":null,"workerid":"1","prename":"Sarah","lastname":"Gonzalez","avatar":"megan.jpg","lineup":"Herren\/Damen","languages":"DE EN","partnerid_fk":"6","partnerid":"6","code":"DEMO6003","partnerName":"Demo Partner","street":"bla 1","zipCode":"bla","city":"bla","workers":"n\/a","email":"test@test.com","phone":"+41414441111","slogan":"Demo Partner zum Erkunden der App"}, ...]

现在我尝试使用此脚本解析 html 文件中的 JSON 输出:

  <script type="text/javascript">
       $.getJSON('<link to php file>', function(data) {
            $.each(data, function(i, appointment) {
                alert('entered each()');
                var id = appointment.appointmentid;

                console.log('appointmentid ' + id);
            });
        });
  </script>

$.getJSON被称为,但是datanull。我究竟做错了什么?

4

1 回答 1

0

你只需要大写iin appointment.appointmentid;

appointment.appointmentId; // <-- since your property has it capitalized
于 2013-01-07T17:34:30.030 回答