CKTIS / PHP
json_decode()
Načíta JSON v UTF-8 ako hodnoty PHP.
Verzia: PHP 8.4; repository runtime, production runtime not attested
Syntax
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixedNačíta JSON v UTF-8 ako hodnoty PHP. Objekt bežne dá stdClass, associative=true vytvorí pole a null sa riadi JSON_OBJECT_AS_ARRAY. Platné JSON null aj syntaktická chyba bežne dajú null. JSON_THROW_ON_ERROR rozlíši chybu výnimkou.
Signatúra
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixed
Výstup príkladu
["stdClass",2,null,"JsonException"]
Príklady
<?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]);
Výsledok
["stdClass",2,null,"JsonException"]