$name = mb_convert_encoding("康林", "GBK", "utf-8");
$usrInfo[] = array('username'=>'zhaogou','age'=>29,'sex'=>'male','tel'=>'028');
$usrInfo[] = array('username'=> mb_convert_encoding("康林", "utf-8", "GBK") ,'age'=>2,'sex'=>'3','tel'=>'4');
//这里必须 utf-8格式???
$jsdata=json_encode($usrInfo);
echo $jsdata;
/*
//如果是索引数组 二维或者一维数组.生成json数据对象属性 就是数组的key
class jstest{
public $name="zhaogou";
public $age=21;
private $sex='male';
public function say(){
echo ".....";
}
}
$jstest = new jstest;
$jsclass=json_encode($jstest);
echo $jsclass;*/
//如果是一个对象,则js数据中不会包含对象中的方法,如果属性是私有的也不能访问到.
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
getJSON获取数据#divframe{ border:1px solid #999; width:500px; margin:0 auto;}
.loadTitle{ background:#CCC; height:30px;}
$(function(){
$("#btn").click(function(){
$.getJSON("sql.php",function(data){
var $jsontip = $("#jsonTip");
var strHtml = "";//存储数据的变量
$jsontip.empty();//清空内容
$.each(data,function(infoIndex,info){
strHtml += "姓名:"+info["username"]+"
";
strHtml += "性别:"+info["sex"]+"
";
strHtml += "Tel:"+info["tel"]+"
";
strHtml += "
"
})
$jsontip.html(strHtml);//显示处理后的数据
})
})
})
http://www.hikanglin.cn/blog//uploadfiles/json_43000.zip