MENU
Decoding
To decode a JSON string $s, use json_decode($s [,$b=false [,$i1=512 [,$i2=0]]]). If $b is true, returned objects will be converted into associative arrays. $i1 specifies the recursion depth. $i2 can be JSON_BIGINT_AS_STRING. For the JSON strings, the names and string values must be enclosed in double quotes. Single quotes are not allowed.RESETRUNFULL
<?php
$a = '{"a":1,"b":2,"c":3,"special-X":100}';
var_dump(json_decode($a));
var_dump(json_decode($a, true));
$b = json_decode($a);
echo $b->{'special-X'}; // - is not allowed originally
$a = '{"num": 12345678901234567890}';
var_dump(json_decode($a));
var_dump(json_decode($a, false, 512, JSON_BIGINT_AS_STRING));
?>
object(stdClass)#1 (4) { ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) ["special-X"]=> int(100) }
array(4) { ["a"]=> int(1) ["b"]=> int(2) ["c"]=> int(3) ["special-X"]=> int(100) }
100
object(stdClass)#2 (1) { ["num"]=> float(1.2345678901235E+19) }
object(stdClass)#2 (1) { ["num"]=> string(20) "12345678901234567890" }