狐的传说
您可以使用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)}几点要记住:json_decode要求字符串是有效的,json否则它将返回NULL。如果解码失败,json_last_error()可用于确定错误的确切性质。确保传入utf8内容,或者json_decode可能出错并只返回一个NULL值。