CKTIS / PHP
JsonException
Hvata pogrešku operacije JSON sa zastavicom JSON_THROW_ON_ERROR.
Verzija: PHP 8.4; repository runtime, production runtime not attested
Sintaksa
catch (JsonException $error) { /* inspect JSON error */ }Hvata pogrešku operacije JSON sa zastavicom JSON_THROW_ON_ERROR. Kod određuje vrstu, primjerice JSON_ERROR_SYNTAX. Valjani JSON null dekodira se redovito i razlikuje od neispravnog ulaza. Zadane zastavice ne uključuju iznimku.
try { json_decode("{",true,512,JSON_THROW_ON_ERROR); }
catch(JsonException $e){$syntax=$e->getCode()===JSON_ERROR_SYNTAX;}
echo json_encode([$syntax,json_decode("null",true,512,JSON_THROW_ON_ERROR)]);
[true,null]
Primjeri
<?php
try { json_decode("{",true,512,JSON_THROW_ON_ERROR); }
catch(JsonException $e){$syntax=$e->getCode()===JSON_ERROR_SYNTAX;}
echo json_encode([$syntax,json_decode("null",true,512,JSON_THROW_ON_ERROR)]);
Rezultat
[true,null]