代码之家  ›  专栏  ›  技术社区  ›  Moon

PHP5和7-json\u last\u错误差异

  •  3
  • Moon  · 技术社区  · 7 年前

    json_last_error() 在PHP7中返回不同的值。

    $input = file_get_contents('php://input');
    $json = json_decode($input, true);
    
    print_r(json_last_error());
    

    curl 'http://localhost/test.php'  -H 'Content-Type: application/json' --compressed
    

    php5返回0(JSON\u ERROR\u NONE)

    我看了官方文件,如果有变化,但我找不到任何信息。

    json_decode() json\u last\u error() 功能?

    1 回复  |  直到 7 年前
        1
  •  4
  •   Qirel    7 年前

    根据 changelog of json_decode() ,任何“falsy”字符串值(表示空字符串, null false )将导致JSON语法错误。所以是的,有一个变化 json解码() 在php5和php7之间。 json_last_error() 但是没有改变。

    json_encode()

    推荐文章