“php essayez JSON Decode” Réponses codées

php json_decode

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

$person = json_decode($personJSON);

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

php essayez 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 Essayez JSON Decode et vérifiez

// 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

Réponses similaires à “php essayez JSON Decode”

Questions similaires à “php essayez JSON Decode”

Plus de réponses similaires à “php essayez JSON Decode” dans PHP

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code