<?php
/* ***json编码***
[1,2,5,7,8,"hello",[6,7,8],{"h":"hello"}]
{"h":"hello","w":"world",[1,2,3]}//h为key,hello为value,即k=>v对,K与v用:隔开,多个k=>v对之间用逗号隔开
*/
$arr=array(1,2,5,8,'hello','xuexi',array('h'=>'Hello','name'=>'xuexi'));
//print_r($arr);
//echo json_encode($arr);//json_encode()把数据转换为Joson格式
//输出:[1,2,5,8,"hello","xuexi",{"h":"Hello","name":"xuexi"}]
?>
<?php
$obj =array('h'=>'hello','w'=>'world',array(3,2,1));
//echo json_encode($obj);
//输出:{"h":"hello","w":"world","0":[3,2,1]}
?>
<?php
//***json解码***
$jsonstr = '{"h":"hello","w":"world","0":[3,2,1]}';
$obj = json_decode($jsonstr);
//print_r($obj);
//输出:stdClass Object ( [h] => hello [w] => world [0] => Array ( [0] => 3 [1] => 2 [2] => 1 ) )
echo $obj->h;
//输出:hello
?>