“PHP Try JSON Decode” Respostas de código

php json_decode

$personJSON = '{"name":"Johny Carson","title":"CTO"}';

$person = json_decode($personJSON);

echo $person->name; // Johny Carson
Grepper

PHP Try JSON Decode

/** Checks if JSON and returns decoded as an array, if not, returns false, 
but you can pass the second parameter true, if you need to return
a string in case it's not JSON */
function tryJsonDecode($string, $returnString = false) {
   $arr = json_decode($string);
  if (json_last_error() === JSON_ERROR_NONE) {
    return $arr;
  } else {
    return ($returnString) ? $string : false;
  }
}
MaestroError

PHP Try JSON Decode e verifique

// Checks if json
function isJson($string) {
   json_decode($string);
   return json_last_error() === JSON_ERROR_NONE;
}

// example
if (isJson($string) {
  // Do your stuff here
}
MaestroError

Respostas semelhantes a “PHP Try JSON Decode”

Perguntas semelhantes a “PHP Try JSON Decode”

Mais respostas relacionadas para “PHP Try JSON Decode” em PHP

Procure respostas de código populares por idioma

Procurar outros idiomas de código