用php怎么生成这种格式的json文件? 20
{"total":239,"rows":[{"code":"001","name":"Name1","addr":"Address11","col4":"col4data...
{
"total":239,
"rows":[
{"code":"001","name":"Name 1","addr":"Address 11","col4":"col4 data"},
{"code":"002","name":"Name 2","addr":"Address 13","col4":"col4 data"},
{"code":"003","name":"Name 3","addr":"Address 87","col4":"col4 data"},
{"code":"004","name":"Name 4","addr":"Address 63","col4":"col4 data"},
{"code":"005","name":"Name 5","addr":"Address 45","col4":"col4 data"},
{"code":"006","name":"Name 6","addr":"Address 16","col4":"col4 data"},
{"code":"007","name":"Name 7","addr":"Address 27","col4":"col4 data"},
{"code":"008","name":"Name 8","addr":"Address 81","col4":"col4 data"},
{"code":"009","name":"Name 9","addr":"Address 69","col4":"col4 data"},
{"code":"010","name":"Name 10","addr":"Address 78","col4":"col4 data"}
]
} 展开
"total":239,
"rows":[
{"code":"001","name":"Name 1","addr":"Address 11","col4":"col4 data"},
{"code":"002","name":"Name 2","addr":"Address 13","col4":"col4 data"},
{"code":"003","name":"Name 3","addr":"Address 87","col4":"col4 data"},
{"code":"004","name":"Name 4","addr":"Address 63","col4":"col4 data"},
{"code":"005","name":"Name 5","addr":"Address 45","col4":"col4 data"},
{"code":"006","name":"Name 6","addr":"Address 16","col4":"col4 data"},
{"code":"007","name":"Name 7","addr":"Address 27","col4":"col4 data"},
{"code":"008","name":"Name 8","addr":"Address 81","col4":"col4 data"},
{"code":"009","name":"Name 9","addr":"Address 69","col4":"col4 data"},
{"code":"010","name":"Name 10","addr":"Address 78","col4":"col4 data"}
]
} 展开
展开全部
$arr1 = array();
$arr3 = array('code', 'name', 'add', 'cole4');
$arr4 = array(" ", " ", " ", "");
//下面用个循环把那些类似下面的数据进行处理,我就不写了
$arr4[0] = "001";
$arr4[1] = "Name 1";
$arr4[2] = "Address 11";
$arr4[3] = col4 data";
$arrtmp = array_combine($arr3, $arr4);
$arr5 = array();
array_push($arr5, $arrtmp);
//缺早上面是循环结束,$arr5里的是那些code, name, addr, col4的数局扮余据
$arr2 = array('桐滚total'=>"239", 'rows'=>$arr5);
echo json_encode($arr2);
$arr3 = array('code', 'name', 'add', 'cole4');
$arr4 = array(" ", " ", " ", "");
//下面用个循环把那些类似下面的数据进行处理,我就不写了
$arr4[0] = "001";
$arr4[1] = "Name 1";
$arr4[2] = "Address 11";
$arr4[3] = col4 data";
$arrtmp = array_combine($arr3, $arr4);
$arr5 = array();
array_push($arr5, $arrtmp);
//缺早上面是循环结束,$arr5里的是那些code, name, addr, col4的数局扮余据
$arr2 = array('桐滚total'=>"239", 'rows'=>$arr5);
echo json_encode($arr2);
追问
我是打算从数据库里面把数据存到数组中,生成类似这个样子的json文件该怎么做呢?
追答
那就是查询数据,然后循环复制。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询