Next I will summarize several articles for my friends on how to determine whether php is a json data. here I have sorted out some articles to help you know how to use php to determine json data, I hope the example will help you. remember that json_encode returns characters... next I will summarize several articles for my friends on how to determine whether php is a json data. here I have sorted out some articles to help you know how to use php to determine json data, I hope the example will help you.
Remember that json_encode returns a string, while json_decode returns an object.
The code is as follows:
function is_not_json($str){ return is_null(json_decode($str)); }
Determine that the data is legal json data. The PHP version is later than 5.3 and the code is as follows:
function is_json($string) { json_decode($string); return (json_last_error() == JSON_ERROR_NONE); }
The json_last_error () function returns an error during the data encoding/decoding process.
Note: The json codec operation string must be UTF8.
The code is as follows:
If it is not json, false is returned.
Article URL:
Reprint ^ at will, but please attach the tutorial address.