PHP » GoLang |
login |
register |
about
|
json_decode(PHP 5 >= 5.2.0, PHP 7, PECL json >= 1.2.0) json_decode — Decodes a JSON string Description
mixed json_decode
( string
$json
[, bool $assoc = FALSE
[, int $depth = 512
[, int $options = 0
]]] )Takes a JSON encoded string and converts it into a PHP variable. Parameters
Return Values
Returns the value encoded in Examples
Example #1 json_decode() examples
<?php The above example will output: object(stdClass)#1 (5) { ["a"] => int(1) ["b"] => int(2) ["c"] => int(3) ["d"] => int(4) ["e"] => int(5) } array(5) { ["a"] => int(1) ["b"] => int(2) ["c"] => int(3) ["d"] => int(4) ["e"] => int(5) } Example #2 Accessing invalid object properties Accessing elements within an object that contain characters not permitted under PHP's naming convention (e.g. the hyphen) can be accomplished by encapsulating the element name within braces and the apostrophe.
<?php Example #3 common mistakes using json_decode()
<?php Example #4
<?php The above example will output: array(1) { [1]=> array(2) { ["English"]=> array(2) { [0]=> string(3) "One" [1]=> string(7) "January" } ["French"]=> array(2) { [0]=> string(3) "Une" [1]=> string(7) "Janvier" } } } Last error: JSON_ERROR_NONE NULL Last error: JSON_ERROR_DEPTH Example #5 json_decode() of large integers
<?php The above example will output: object(stdClass)#1 (1) { ["number"]=> float(1.2345678901235E+19) } object(stdClass)#1 (1) { ["number"]=> string(20) "12345678901234567890" } Notes
Changelog
See Also
|
more
Recently updated
more
Most requested
more
Last requests
|