CKTIS / PHP
JsonException
Vangt fouten van JSON-bewerkingen met JSON_THROW_ON_ERROR.
Versie: PHP 8.4; repository runtime, production runtime not attested
Syntax
catch (JsonException $error) { /* inspect JSON error */ }Vangt fouten van JSON-bewerkingen met JSON_THROW_ON_ERROR. De code geeft de foutsoort, bijvoorbeeld JSON_ERROR_SYNTAX. Geldige JSON null decodeert normaal en blijft te onderscheiden van onjuiste invoer. De standaardvlaggen schakelen deze uitzondering niet in.
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]
Voorbeelden
<?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)]);
Resultaat
[true,null]