json_encode默认转成字符串, 设置第二参数,true表示转成json数组。 return json_encode(['data' => $res],true); //打印//{"data":[{"counts":1,"writer":"title1"},{"counts":2,"writer":"title2"}]}
以 mysql 为例 mysql_query('set names utf8'); $rs = mysql_query($sqlstr) or die(mysql_error()); while($row=mysql_fetch_assoc($rs)) $res[] = $row; echo json_encode(['data' => $res]);
mysql_query('set names utf8'); $rs = mysql_query($sqlstr) or die(mysql_error()); while($row=mysql_fetch_assoc($rs)) $res[] = $row; echo json_encode(['data' => $res]);
在你的查询指令($sqlstr)中指定,顺序及名称
21,887
社区成员
140,363
社区内容
加载中
试试用AI创作助手写篇文章吧