我的尝试是使一个分页和这就是我的Ajax请求页面:添加两个对象到一个json_encode在PHP
while ($file = $query->fetch(PDO::FETCH_ASSOC)) {
$arrayFetch[] = [
'id' => $file['id'],
'name' => $file['name']
];
$lastId = $file['lastId'];
}
// For simplify: Here is another query code for get the the result of $count
$count = $query->rowCount();
所以,我现在有变数$arrayFetch
和$count
。
UPDATE:
我实际上是json_encode代码:
echo '{"user":'.json_encode($arrayFetch).'}';
输出是:
{"user":[{ "id":1,"name":"toby"},....]}
我要的是增加一个第二个对象是这样的:
{"user":[{ "id":1,"name":"toby"},....]},
{"pagination":[{ "count":10" }]} // THIS
那不工作,这只是一个例子来说明什么,我试图存档:
echo '{"user":'.json_encode($arrayFetch).'},{ "pagination": [{ "count" : '.$count.' }] ';
这不是JSON。 –
这很好,但明白没有方括号的JSON数组不是JSON。 –