json_encode和json_decode
Posted hyh123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json_encode和json_decode相关的知识,希望对你有一定的参考价值。
<?php $json = ‘{"a":1,"b":2,"c":3,"d":4,"e":5}‘; var_dump(json_decode($json)); var_dump(json_decode($json, true)); ?>
object(stdClass)#1 (5) { ["a"] => int(1) ["b"] => int(2) ["c"] => int(3) ["d"] => int(4) ["e"] => int(5) } array(5) { ["a"] => int(1) ["b"] => int(2) ["c"] => int(3) ["d"] => int(4) ["e"] => int(5) }
可以看出 json_decode($data,true)输出的一个关联数组,由此可知json_decode($data)输出的是对象,而json_decode("$arr",true)是把它强制生成PHP关联数组.
以上是关于json_encode和json_decode的主要内容,如果未能解决你的问题,请参考以下文章