语法
mixed json_decode ($json_string [,$assoc = false [, $depth = 512 [, $options = 0 ]]])
-
json_string: 待解码的 JSON 字符串,必须是 UTF-8 编码数据
-
assoc: 当该参数为 TRUE 时,将返回数组,FALSE 时返回对象。
需要转换为数组时必须使用
json_decode($res,true);
示例
$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)
}