为什么我的json_encode无效

时间:2018-02-23 15:46:04

标签: php json

为什么json_encode无效。当我在数组中有两个值时,它正在工作,但现在有三个,它只显示没有。

在json_encode中使用json_last_error会显示以下错误:

Warning: json_encode() expects parameter 2 to be integer, string given in

这是数组:

[8000] => Array
    (
        [employee_id] => AAAAA
        [name] => tom  
        [tick] => 1
    )

[8001] => Array
    (
        [employee_id] => BBBB
        [name] => harry
        [tick] => 1
    )

[8002] => Array
    (
        [employee_id] => CCCC
        [name] => sam
        [tick] => 1
    )

[8003] => Array
    (
        [employee_id] => DDD
        [name] => ricky
        [tick] => 1
    )

这是json编码代码$datas是数组:

$json = json_encode($datas, json_last_error);

var_dump($json);

1 个答案:

答案 0 :(得分:1)

json_last_error()是一个函数,而不是option

$json = json_encode($datas); 
$error = json_last_error(); 
if ($error == JSON_ERROR_NONE) {
   var_dump($json);
}