332   PHP

实例代码

$arr=array(
	'a'=>'one',
	'b'=>array(
		'c',
		'd'
		)
	);

// 将数组转化为json字符串
$str = json_encode($arr);
var_dump($str);

// 将json字符串转化为对象
$obj = json_decode($str);
var_dump($obj);
echo $obj->a;

// 将json字符串转化为数组
$new_arr = json_decode($str,true);
var_dump($new_arr);
echo $new_arr['a'];



Leave a Reply

Your email address will not be published. Required fields are marked *