json_decode() returns null issues

前端 未结 10 2146
误落风尘
误落风尘 2020-12-03 11:47

I\'ve an issue with my JSON. It works returns correctly in PHP 5.3 (so I can\'t use json_last_error()), and it returns successfully when I copy string explicitly into json_d

10条回答
  •  一生所求
    2020-12-03 12:08

    Since PHP 7.3, the json_decode function will accept a new JSON_THROW_ON_ERROR option that will let json_decode throw an exception instead of returning null on error.


    Example:

    try {  
      json_decode("{", false, 512, JSON_THROW_ON_ERROR);  
    }  
    catch (\JsonException $exception) {  
      echo $exception->getMessage(); // displays "Syntax error"  
    }
    

提交回复
热议问题