TP5.1 无法正常判断json格式字符串

浏览:2160 发布日期:2018/01/30 分类:ThinkPHP5专区
$a = "sdgsdgsdgsdg";
$b = '{"name":"ewvwev"}';
json_decode($a);
$a_is_json_2 = (json_last_error() == JSON_ERROR_NONE);
json_decode($b);
$b_is_json_2 = (json_last_error() == JSON_ERROR_NONE);
return [
    'a_is_json_1' => is_null(json_decode($a)),
    'a_is_json_2' => $a_is_json_2,
    'b_is_json_1' => is_null(json_decode($b)),
    'b_is_json_2' => $b_is_json_2,
];
得到的结果竟然是:{
  "a_is_json_1": true,
  "a_is_json_2": false,
  "b_is_json_1": false,
  "b_is_json_2": true
}
最佳答案
评论() 相关
后面还有条评论,点击查看>>