Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.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
Php 从MySQL解码JSON_Php_Mysql_Json_Decode_Encode - Fatal编程技术网

Php 从MySQL解码JSON

Php 从MySQL解码JSON,php,mysql,json,decode,encode,Php,Mysql,Json,Decode,Encode,我在MySQL数据库中有这样的JSON字符串 我将MySQL中的数据放入$string中,然后使用此函数对其进行解码 但结果一无所获。 然后我尝试将$string更改为 接下来,我使用与上面相同的函数,效果很好。 在从mysql解码之前,我们应该做些什么 谢谢您拥有的数据的外层不是数组,事实上,数据中根本没有任何数组。不要在PHP中使用[0]。使用 echo $json_a['string1']['substring1']; var_dump$string是什么样子的?@MarkusMülle

我在MySQL数据库中有这样的JSON字符串

我将MySQL中的数据放入$string中,然后使用此函数对其进行解码

但结果一无所获。 然后我尝试将$string更改为

接下来,我使用与上面相同的函数,效果很好。 在从mysql解码之前,我们应该做些什么


谢谢

您拥有的数据的外层不是数组,事实上,数据中根本没有任何数组。不要在PHP中使用[0]。

使用

echo $json_a['string1']['substring1'];

var_dump$string是什么样子的?@MarkusMüller:结果是这样的字符串174{string1:{substring1:1234},string2:{substring2:substring2.1,substring3:substring3.1,substring4:{substring4.1:1234,substring4.2:1234,substring4.3:1234}}@MarkusMüller怎么样?对不起,我在发布这个问题时弄错了,我已经编辑好了。
$json_a = json_decode($string,true); 
echo $json_a['string1']['substring1'];
$string = '{"string1":{"substring1":1234},"string2":{"substring2":"substring2.1","substring3":"substring3.1","substring4":{"substring4.1":1234,"substring4.2":1234,"substring4.3":1234}}}';
echo $json_a['string1']['substring1'];