How to validate JSON in PHP?

后端 未结 5 2070
没有蜡笔的小新
没有蜡笔的小新 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:32

    $ob = json_decode($json);
    if($ob === null) {
     // $ob is null because the json cannot be decoded
    }
    

提交回复
热议问题