CKTIS / PHP
json_decode()
Liest UTF-8-JSON als PHP-Werte.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixedLiest UTF-8-JSON als PHP-Werte. Objekte werden standardmäßig stdClass, associative=true erzeugt Arrays und null folgt JSON_OBJECT_AS_ARRAY. Gültiges JSON null und Syntaxfehler ergeben standardmäßig null. JSON_THROW_ON_ERROR kennzeichnet den Fehler per Ausnahme.
Signatur
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixed
Ausgabe des Beispiels
["stdClass",2,null,"JsonException"]
Beispiele
<?php
$object = json_decode("{\"x\":2}"); $map = json_decode("{\"x\":2}",true);
try { json_decode("[",true,512,JSON_THROW_ON_ERROR); } catch (JsonException $e) { $bad = get_class($e); }
echo json_encode([get_class($object),$map["x"],json_decode("null"),$bad]);
Ergebnis
["stdClass",2,null,"JsonException"]