This article mainly introduces the generation of JSON by PHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
<?php $arr = array( 'id'=>1, 'name'=>'andros230' ); $result = array( 'code'=>'200', 'msg'=>'成功', 'data'=>$arr ); echo json_encode($result,JSON_UNESCAPED_UNICODE); ?>
Output: {"code":" 200","msg":"success","data":{"id":1,"name":"andros230"}}
Note: JSON_UNESCAPED_UNICODE requires PHP5 to solve Chinese garbled characters. Version 4 or above
Related recommendations:
The above is the detailed content of PHP generates JSON. For more information, please follow other related articles on the PHP Chinese website!