json to php in php index error [duplicate]

时间:2021-02-20 21:29:38

This question already has an answer here:

这个问题在这里已有答案:

I have a json text like this:

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

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

I want convert it to array:

我想将它转换为数组:

$arr = json_encode($text,true);

Now I want call $arr['id'] But I get index error.

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

what is my wrong?

我错了什么?

1 个解决方案

#1


2  

json_encode() - change an array to the json

json_encode() - 将数组更改为json

json_decode() - change json to the array/object

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

You should use json_decode.

你应该使用json_decode。

#1


2  

json_encode() - change an array to the json

json_encode() - 将数组更改为json

json_decode() - change json to the array/object

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

You should use json_decode.

你应该使用json_decode。