php 用mysqli的json_encode()转换出来 全是对象的问题

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/6 0006
 * Time: 15:33
 */
//查询所有用户
error_reporting(E_ALL ^ E_DEPRECATED);
$link=new mysqli('localhost','root','root','pho');

if($link->connect_errno){
    die($link->connect_errno);
}

/*分页
要知道 $size 自己定义显示几行
$length 总行数
$start 开始页码*/

$size=3;
$start=$_POST['num']-1;
$startpage=3*$start;

$sql="select id,name from admin_biao limit $startpage,$size";
$res=$link->query($sql);

$array=array();
$inum=0;
while ($row=$res->fetch_assoc()){
    $array[$inum]=$row;
    $inum++;
}

$data=array();
$data['cont']=$array;

$data=json_encode($data);
header('content-type:application/json');
echo $data;
?>

因为  在$inum 如果在while里面  先执行了++;就会返回的json全是对象、

如果把++在最后执行,就该是数组的还是数组。

posted @ 2018-09-07 11:11  盖大楼  阅读(776)  评论(0编辑  收藏  举报