json_decode—对JSON格式的字符串进行解码。
json_decode函数说明
(PHP5>=5.2.0,PECLjson>=1.2.0)
json_decode—对JSON格式的字符串进行解码
函数定义编辑
mixedjson_decode(string$json[,bool$assoc])
接受一个JSON格式的字符串并且把它转换为PHP变量
参数
json
待解码的jsonstring格式的字符串。
assoc
当该参数为TRUE时,将返回array而非object。
返回值
返回一个对象,如果assoc参数选项为true,将会返回一个关联数组。
json_decode实例说明
用json_decode()函数将JSON格式的字符串编码。
<?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)
}[1]
总之,json_decode给大家简单的介绍了一些,希望大家多看看。