note 116083 deleted from function.json-decode by salathe

From: Date: Mon, 21 Sep 2020 15:00:13 +0000
Subject: note 116083 deleted from function.json-decode by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215417@lists.php.net to get a copy of this message
Note Submitter: qrworld.net ---- I found this post http://softontherocks.blogspot.com/2014/11/funcion-jsondecode-de-php.html They show there an example of using json_decode: $json = '{"users":[{ "user": "Carlos", "age": 30, "country": "Spain" }, { "user": "John", "age": 25, "country": "United States" }]}';   // Decodificamos la cadena JSON $obj = json_decode($json); var_dump($obj); /* devuelve object(stdClass)#1 (1) { ["users"]=> array(2) { [0]=> object(stdClass)#2 (3) { ["user"]=> string(6) "Carlos" ["age"]=> int(30) ["country"]=> string(5) "Spain" } [1]=> object(stdClass)#3 (3) { ["user"]=> string(4) "John" ["age"]=> int(25) ["country"]=> string(13) "United States" } } } */   // Devolvemos el resultado como array $obj = json_decode($json, true); var_dump($obj); /* devuelve array(1) { ["users"]=> array(2) { [0]=> array(3) { ["user"]=> string(6) "Carlos" ["age"]=> int(30) ["country"]=> string(5) "Spain" } [1]=> array(3) { ["user"]=> string(4) "John" ["age"]=> int(25) ["country"]=> string(13) "United States" } } } */   // Limitamos la profundidad de la recursividad a 2 $obj = json_decode($json, true, 2); var_dump($obj); /* devuelve NULL -> la profundidad es 4 */

« previous php.notes (#215417) next »