处理json_encode()后数组为非标准数组(object)

<?php
//header("Content-type:application/json");
$array = array('A'=>'a', 'B'=>'b', 'C'=>'c');

$j_arr = json_encode($array);


//1.当解析后为非标准格式(Object)
$res = json_decode($j_arr);
echo $res -> A; //输出a

//2.$res为object类型,使用(array)强转换
$arr = (array)$res; 
$arr变回数组,不是object

//3.json_decode($res, TRUE); 最好滴方法
$arr = json_decode($res, TRUE);
$arr变成数组

?>

 

posted @ 2013-04-03 19:51  seabxyh  阅读(337)  评论(0)    收藏  举报