Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将JSON字符串数组转换为PHP数组_Php - Fatal编程技术网

将JSON字符串数组转换为PHP数组

将JSON字符串数组转换为PHP数组,php,Php,我在PHP中有一个JSON数组: $array={"definitions":[ {"text":"Informal One who is proficient at using or programming a computer; a computer buff.", "attribution":"from The American Heritage\u00ae Dictionary of the English Language, 4th Edition" },

我在PHP中有一个JSON数组:

$array={"definitions":[
    {"text":"Informal One who is proficient at using or programming a computer; a computer buff.",
     "attribution":"from The American Heritage\u00ae Dictionary of the English Language, 4th Edition"
    },
    {"text":"Informal One who uses programming skills to gain illegal access to a computer network or file.",
     "attribution":"from The American Heritage\u00ae Dictionary of the English Language, 4th Edition"
    },
    {"text":"Informal One who enthusiastically pursues a game or sport: a weekend tennis hacker. ",
     "attribution":"from The American Heritage\u00ae Dictionary of the English Language, 4th Edition"
    },
    {"text":"See hackie.",
     "attribution":"from The American Heritage\u00ae Dictionary of the English Language, 4th Edition"
    }
]}
无论我尝试什么,我都无法访问元素。我需要访问如下元素:
$array[0][“定义”][0][“文本”]

尝试使用内置库

或者,如果您运行的是较旧版本的PHP,我可以使用PEAR服务器\u JSON()

$data = json_decode($your_json_string, TRUE);
第二个参数将解码的json字符串转换为关联数组

比如说

json_decode('{"foo":"bar"}', true); // returns array("foo" => "bar")

这是我的错误,我的数组实际上是一个字符串。不要重复你自己的问题。有超过1个代表的人应该更清楚。