PHP - json_decode
Trieda
Metóda - json_decode
(PHP 5 >= 5.2.0, PECL json >= 1.2.0, PHP 7)
Converts a JSON string into a PHP variable. On error, the
json_last_error() function can be used to determine the exact
error.
Procedurálne
- function json_decode (string $json, bool $assoc = false, int $depth = 512, int $options = 0) : mixed
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $json | string | The JSON to decode in the UTF-8 format. | |
| $assoc | bool | false | If this parameter is set to |
| $depth | int | 512 | The depth limit of the recursion. |
| $options | int | 0 | We can set 2 decoding options as a bitmask:
|
Mávratovej hodnoty
Vracia: mixed
Returns the appropriate type of the JSON representation as a PHP variable. If
JSON couldn't be decoded or the data are deeper than the recursion limit,
returns null.
Príklady
<?php
$myJson = '{"name": "John", "age": "42", "male": true}';
var_dump(json_decode($myJson));
Súvisiace manuály
- function json_encode (mixed $value, int $depth = 512) : string
