Exemple de code pour traiter du JSON en PHP
$json = '{ "Image": { "Width": 800, "Height": 600, "Title": "View from 15th Floor", "Thumbnail": { "Url": "http://www.example.com/image/481989943", "Height": 125, "Width": 100 }, "Animated" : false, "IDs": [116, 943, 234, 38793] } }'; $a = json_decode($json , true); $b = json_decode($json); var_dump($a); //array var_dump($b); //object
Résultat du 1er var_dump
array(1) { ["Image"]=> array(6) { ["Width"]=> int(800) ["Height"]=> int(600) ["Title"]=> string(20) "View from 15th Floor" ["Thumbnail"]=> array(3) { ["Url"]=> string(38) "http://www.example.com/image/481989943" ["Height"]=> int(125) ["Width"]=> int(100) } ["Animated"]=> bool(false) ["IDs"]=> array(4) { [0]=> int(116) [1]=> int(943) [2]=> int(234) [3]=> int(38793) } } }
Résultat du 2eme var_dump
object(stdClass)#3 (1) { ["Image"]=> object(stdClass)#1 (6) { ["Width"]=> int(800) ["Height"]=> int(600) ["Title"]=> string(20) "View from 15th Floor" ["Thumbnail"]=> object(stdClass)#2 (3) { ["Url"]=> string(38) "http://www.example.com/image/481989943" ["Height"]=> int(125) ["Width"]=> int(100) } ["Animated"]=> bool(false) ["IDs"]=> array(4) { [0]=> int(116) [1]=> int(943) [2]=> int(234) [3]=> int(38793) } } }