Answer the question
In order to leave comments, you need to log in
json string validation?
You need to check if the incoming element is a json string.
public static function isJson($string)
{
json_decode($string);
if (json_last_error() === JSON_ERROR_NONE) {
return true;
}
return false;
// или
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
}
// и еще так пробовал
json_decode(123) // будет true
Answer the question
In order to leave comments, you need to log in
when will you learn to read the documentation?
open php.net/manual/ru/function.json-decode.php and see
Note:
PHP implements a superset of JSON, which is described in the original » RFC 7159.
JSON can represent four primitive types (strings, numbers, booleans, and null)
and two structured types (objects and arrays) .
There are a lot of correct solutions here https://stackoverflow.com/questions/6041741/fastes...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question