note 122689 deleted from function.json-decode by salathe
| From: | salathe@php.net | Date: | Mon, 21 Sep 2020 15:01:10 +0000 |
| Subject: | note 122689 deleted from function.json-decode by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215432@lists.php.net to get a copy of this message | ||
Note Submitter: Adrian H
----
Be careful with strings encoded twice, json_decode will just return a string!
Ex: php -a
php >
php >
php > $a = ['b'=> 3];
php > $x = json_encode($a);
php > $x = json_encode($x);
php >
php > var_dump($x);
string(11) ""{\"b\":3}""
php >
php > var_dump(json_decode($x));
string(7) "{"b":3}" // this is kinda unexpected!
php >
php >
php > var_dump(json_decode(json_decode($x)));
object(stdClass)#1 (1) {
["b"]=>
int(3)
}