CKTIS / PHP
json_decode()
Leest UTF-8-JSON als PHP-waarden.
Versie: PHP 8.4; repository runtime, production runtime not attested
Syntax
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixedLeest UTF-8-JSON als PHP-waarden. Objecten worden standaard stdClass, associative=true geeft arrays en null volgt JSON_OBJECT_AS_ARRAY. Geldige JSON null en een syntaxisfout geven standaard null. JSON_THROW_ON_ERROR markeert de fout met een uitzondering.
Signatuur
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixed
Uitvoer van het voorbeeld
["stdClass",2,null,"JsonException"]
Voorbeelden
<?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]);
Resultaat
["stdClass",2,null,"JsonException"]