警告:json_decode()期望参数1为字符串

时间:2015-08-19 13:47:06

标签: php json

我使用json_encode方法将PHP数组插入mySql,如下所示:

["11","10","4"]

现在我需要转换为php数组:

$me = ["11","10","4"];
$you = json_decode($me, true);
echo $you;

但结果我看到: Warning: json_decode() expects parameter 1 to be string, array given in C:\xampp\htdocs\test\test.php on line 5

如何解决这个问题?!

1 个答案:

答案 0 :(得分:2)

您的问题是$me不是字符串。您只需将其封装在单引号中即可进行更改。

$me = '["11","10","4"]';
$you = json_decode($me);
print_r($you);  // becasue its now a PHP array, 
                // copy/paste will get you every time