json在php索引错误中的数组

时间:2016-08-09 19:45:16

标签: php arrays json

我有一个像这样的json文本:

$text ='{"id":"12","count":"1","1":{"gkey":"g_c5218"},"0":{"gkey":"g_4b4c6"}}';

我想将其转换为数组:

$arr = json_encode($text,true);

现在我想要调用$arr['id']但是我得到索引错误。

我错了什么?

1 个答案:

答案 0 :(得分:2)

json_encode() - 将数组更改为json

json_decode() - 将json更改为数组/对象

您应该使用json_decode