我想生成嵌套的json的格式不知道怎么做。。。
比方说我要查询用户=aa的数据,可能不止一行:$row=mysql_fetch_array($rs);
结果可能是多行的: {{id=1,account=123,depart=xxx},{id=22,account=323,depart=kkk}}
我希望生成这样的json格式:
{user:aa,[{id=1,account=123,depart=xxx},{id=22,account=323,depart=kkk}]}应该怎么做?
数组拼凑起来不就可以了
数组拼凑起来不就可以了
howto?
格式应该是这样的:
{user:aa,result:[{id=1,account=123,depart=xxx},{id=22,account=323,depart=kkk}]}
字符串的双引号我省略了。
$ar=array();$ar['user']='aa';while($row=mysql_fetch_array($rs)){ $ar['result'][]=$row;}echo json_encode($ar);
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号