CKTIS / PHP
json_decode()
Prebere JSON v UTF-8 kot vrednosti PHP.
Različica: PHP 8.4; repository runtime, production runtime not attested
Sintaksa
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixedPrebere JSON v UTF-8 kot vrednosti PHP. Objekt privzeto da stdClass, associative=true ustvari polje in null sledi JSON_OBJECT_AS_ARRAY. Veljavni JSON null in skladenjska napaka privzeto dasta null. JSON_THROW_ON_ERROR napako loči z izjemo.
Podpis
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixed
Izhod primera
["stdClass",2,null,"JsonException"]
Primeri
<?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]);
Rezultat
["stdClass",2,null,"JsonException"]