How to validate JSON in PHP?

后端 未结 5 2065
没有蜡笔的小新
没有蜡笔的小新 2020-12-15 16:41

Is there any way to check that a variable is a valid JSON string in PHP without using json_last_error()? I don\'t have PHP 5.3.3.

5条回答
  •  太阳男子
    2020-12-15 17:41

    $data = json_decode($json_string);
    if (is_null($data)) {
       die("Something dun gone blowed up!");
    }
    

提交回复
热议问题