[PHP] json_decode()

json_decode() (funzione PHP) decodifica una stringa JSON, restituendola sotto forma di oggetto o array.

tips&tricks

Sintassi

json_decode($stringa, $true[facoltativo], $profondità[facoltativo])
parametro descrizione
$stringa La stringa json da decodificare
$true Valore booleano. Se true, restituisce un array; se false (default) restituisce un oggetto.
$profondità In costruzione

Esempi

$json = '{"a":1,"b":2,"c":3}';
var_dump(json_decode($json));
var_dump(json_decode($json, true));

/* RISULTATO
object(stdClass)#1 (3) {
  ["a"]=>  int(1)
  ["b"]=>  int(2)
  ["c"]=>  int(3)
}
array(3) {
  ["a"]=>  int(1)
  ["b"]=>  int(2)
  ["c"]=>  int(3)
}
*/

Contenuti correlati

Fonti esterne

funzioni php, php

Related Articles

0 Comment