格式如下:[{"uid":1,"uname":"York","tag":{"2":"beijing","6":"chaoyang"}},{"uid":4,"uname":"Lee","tag":{"2":"beijing","8":"haidian"}}]这种数据怎么生成啊
php中将数组格式换换为json格式可以使用 json_encode函数。示例代码如下:<?php //定义数组 $arr=array('city'=>array('北京','上海','广州'),'order'=>array(1,2,3)); //将数组转换为json格式 var_dump(json_encode($arr)) ; ?>json格式效果:
$arr=array(array('uid'=>1,'uname'=>'York','tag'=>array('2'=>'beijing','6'=>'chaoyang')),array('uid'=>4,'uname'=>'Lee','tag'=>array('2'=>'beijing','8'=>'haidian')));echo json_encode($arr);