首页 > 技术文章 > php json_decode 和json_encode

wobeinianqing 2017-06-21 22:10 原文

json_decode 
(PHP 5 >= 5.2.0, PECL json >= 1.2.0) 

json_decode — 对 JSON 格式的字符串进行编码 

说明 
mixed json_decode ( string $json [, bool $assoc ] ) 
接受一个 JSON 格式的字符串并且把它转换为 PHP 变量 

参数 

json 
待解码的 json string 格式的字符串。 

assoc 
当该参数为 TRUE 时,将返回 array 而非 object 。 

即:当assoc 为true 的时候

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; 

$a =  json_decode ( string $json  ,  true) ;

echo $a['aa'];//可以使用a['aa'] 这种形式获取对应的值

 

推荐阅读