How handling error of json decode by try and catch

前端 未结 4 1459
栀梦
栀梦 2021-02-12 16:20

I am unable to handle JSON decode errors. Here is my code:

try {
    $jsonData = file_get_contents($filePath) . \']\';
           


        
4条回答
  •  再見小時候
    2021-02-12 16:37

    Another way to handle json decode error:-

    if ($jsonObj === null && json_last_error() !== JSON_ERROR_NONE) {
       echo "json data is incorrect";
    }
    

提交回复
热议问题