我想轉換對象JSON編碼數組的數組的工作,我作出這樣JSON編碼不與對象
$allVisits = $mapper->getAllVisits($year, $month);
echo json_encode($allVisits);
和這裏的是getAllVisists方法
function getAllVisits($year, $month) {
$where = array(
'year = ?' => $year,
'month = ?' => $month
);
$resultSet = $this->getDbTable()->fetchAll($where);
$visitsEntries = array();
foreach ($resultSet as $row) {
$entry = new Visits_Model_Visit();
$entry->setId($row->visit_id)
->setDay($row->day)
->setDate($row->date)
->setTarget($row->target)
->setStatus($row->visit_status)
->setTime($row->visit_time);
$visitsEntries[] = $entry;
}
return $visitsEntries;
}
當我附和$ allVisits的大小返回正確的記錄數,但在js中的值是空的,像這樣[{},{},{},{}]
編輯
當我的print_r($ allVisists)brfore編碼它返回
Array
(
[0] => Visits_Model_Visit Object
(
[day:private] => sunday
[date:private] => 2012-03-06
[target:private] => شسي
[id:private] => 1
[status:private] => 0
[time:private] => 12:00:00
)
[1] => Visits_Model_Visit Object
(
[day:private] => sunday
[date:private] => 2012-03-06
[target:private] => clinnics
[id:private] => 4
[status:private] => 0
[time:private] => 00:00:00
)
[2] => Visits_Model_Visit Object
(
[day:private] => Tuesday
[date:private] => 2012-03-06
[target:private] => clinnics
[id:private] => 5
[status:private] => 0
[time:private] => 00:00:00
)
[3] => Visits_Model_Visit Object
(
[day:private] => Wednesday
[date:private] => 2012-03-28
[target:private] => ??????? ???????
[id:private] => 7
[status:private] => 0
[time:private] => 12:00:00
)
)
在調用'json_encode'之前,您是否嘗試過'print_r($ allVisits)'? – jerrymouse 2012-03-13 12:15:14
它正確地打印出陣列 – palAlaa 2012-03-13 12:35:14