语法
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)
}
本文深入解析PHP中使用json_decode函数进行JSON数据解码的过程。详细介绍了如何通过设置参数来控制解码结果是对象还是数组,提供了具体的代码示例,帮助读者理解JSON数据的正确解析方式。
936

被折叠的 条评论
为什么被折叠?



