好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php 利用json_decode强制json数据转换成数组 - php数组

php 利用json_decode强制json数据转换成数组

一篇php 利用json_decode强制json数据转换成数组的简单应用实例参考文档,我们利用了var_dump(json_decode($str,true)); 就把json转换成我们想要的数据了,代码如下:

$a [ 'd' ][]=1;  $a [ 'd' ][]=2;  echo   $str =json_encode( array ( $a ));  var_dump(json_decode( $str )); 

转换代码,代码如下:

array (1) {    [0]=>    object(stdClass)#1 (1) {      [ "d" ]=>       array (2) {        [0]=>        int(1)        [1]=>        int(2)      }    }  } 

看到了吧这是一个数组里面放置一个对象,我们强制json_decode结果转换为数组吧——把第四行加上参数,代码如下:

var_dump(json_decode( $str ,true));  //开源代码phpfensi测试数据   array (1) {    [0]=>     array (1) {      [ "d" ]=>       array (2) {        [0]=>        int(1)        [1]=>        int(2)      }    }  }

查看更多关于php 利用json_decode强制json数据转换成数组 - php数组的详细内容...

  阅读:45次