php json_encode 函数将编码值转为json格式
创建一个变量数组$age,其值为bill=35,Elon=37,steve=45,通过json_encode函数进行转换为json 格式。
1 <!DOCTYPE html>
2 <html>
3 <body>
4 <?php
5 $age=array("Bill"=>35,"Elon"=>37,"Steve"=>45);
6 echo json_encode($age);
7
8 ?>
9 </body>
10 </html>
返回结果
{"Bill":35,"Elon":37,"Steve":45}
评论