Tag: json_decode

  • PHP: json_decode

    json_decode (PHP 5 >= 5.2.0, PECL json >= 1.2.0, PHP 7) json_decode — 对 JSON 格式的字符串进行编码 说明 mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] ) 接受一个 JSON 格式的字符串并且把它转换为 PHP 变量 参数 json 待解码的 json string 格式的字符串。 This function only works with…

  • json_decode 转换json对象为数组需注意true 你加了吗?

    代码如下 复制代码 $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)); array(1) { [0]=> array(1) { [“d”]=> array(2) { [0]=> int(1) [1]=> int(2) } } }