我對json_encode沒有經驗,我試圖返回一個應該叫做aaData的陣列的arrray - 對於DataTables with server-side processing。json_encode不打印陣列名稱
輸出應該是這樣的:
{
"sEcho": 3,
"iTotalRecords": 57,
"iTotalDisplayRecords": 57,
"aaData": [
[
"Gecko",
"Firefox 1.0",
"Win 98+/OSX.2+",
"1.7",
"A"
],
[
"Gecko",
"Firefox 1.5",
"Win 98+/OSX.2+",
"1.8",
"A"
],
...
]
}
但我的PostgreSQL 8.4驅動的PHP腳本的實際工作輸出
if (isset($_REQUEST['json'])) {
$aaData = array();
while ($row = $sth->fetch(PDO::FETCH_NUM)) {
array_push($aaData, $row);
}
print json_encode($aaData);
}
實際上是缺少外支架(對象是怎樣的?)和aaData name:
[
[ .... ],
[ .... ],
[ .... ]
]
你會怎麼做這是最好的?
這給了我{ 「aaData」:空} –
隨着$ ARR [ 'aaData'] =陣列();在它之間工作,謝謝 –
@AlexanderFarber是的。我也更新了我的帖子。 –