php 显示一个干净的,易被解析的json

header("Content-type: text/html; charset=utf-8");
//试着从数据库里读取一条数据放进来
$con = mysql_connect("localhost","root","root");
mysql_query("SET NAMES 'utf8'"); 
mysql_select_db("yun", $con);
if (!$con){die('Could not connect: ' . mysql_error());}
$s=mysql_query("select * from ofuser");
while($ss = mysql_fetch_array($s)){
$a[]=$ss['username'];
$b[]=$ss['phone'];
$c[]=$ss['nickname'];
}
foreach ($a as $k => $r) {
     $Arr4[] = array('username'=>urlencode($a[$k]),'phone'=>$b[$k],'nickname'=>$c[$k]);
}
//print_r ($Arr4);
echo urldecode(json_encode($Arr4));

原文地址:https://www.cnblogs.com/hellowzd/p/4210689.html