Fastest way to check if a string is JSON in PHP?
问题 I need a really, really fast method of checking if a string is JSON or not. I feel like this is not the best way: function isJson($string) { return ((is_string($string) && (is_object(json_decode($string)) || is_array(json_decode($string))))) ? true : false; } Any performance enthusiasts out there want to improve this method? 回答1: function isJson($string) { json_decode($string); return (json_last_error() == JSON_ERROR_NONE); } 回答2: Answer to the Question The function json_last_error returns