PHP 中关于json二个函数

这个PHP 本身有二个函数 : 
 1. json_encode( array 或 object) 这个是用来把对象 或 数组转换为 JSON格式数据;
 2. json_decode(string ,  boolen[数组为true,对象不用设置]) 这个是把现有的JSON数据转化为 PHP 数组或对象.
式例: 
$a = array(1 => 'a', 2 => 'b', 3 => 'c', 4 => 'd');
$b = json_encode($a);
echo $b;     // 这里得到字串 "{"1":"a","2":"b","3":"c","4":"d"}"
$c = json_decode($b, true);
var_dump($c);  // 这里得到$a数组
如果JSON数据是一个数据, 转化时建议把json_decode函数的第二个参数设为true, 对象则不用.

你可能感兴趣的:(PHP 中关于json二个函数)