CKTIS / PHP
json_decode()
Прочита JSON в UTF-8 като стойности на PHP.
Версия: PHP 8.4; repository runtime, production runtime not attested
Синтаксис
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixedПрочита JSON в UTF-8 като стойности на PHP. Обектът по подразбиране дава stdClass, associative=true създава масив, а null следва JSON_OBJECT_AS_ARRAY. Валиден JSON null и синтактична грешка по подразбиране дават null. JSON_THROW_ON_ERROR отличава грешката с изключение.
Сигнатура
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixed
Изход от примера
["stdClass",2,null,"JsonException"]
Примери
<?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]);
Резултат
["stdClass",2,null,"JsonException"]