note 126586 deleted from function.json-decode by cmb

From: Date: Sat, 13 Nov 2021 17:28:57 +0000
Subject: note 126586 deleted from function.json-decode by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217200@lists.php.net to get a copy of this message
Note Submitter: leo_koester at hotmal dot com ---- This function seems to have an undocumented return as string if the supplied json is "enveloped" as a string itself. $result1 = json_decode("{\"field1\":true,\"field2\":\"Success\",\"field3\":0,\"field4\":1.0}", true ); $result2 = json_decode('"{\"field1\":true,\"field2\":\"Success\",\"field3\":0,\"field4\":1.0}"', true ); A var_dump($result1) will show the expected result: array(4) { ["field1"]=> bool(true) ["field2"]=> string(7) "Success" ["field3"]=> int(0) ["field4"]=> float(1) } While var_dump($result2) will just result in a string instead of an array, or even null: string(58) "{"field1":true,"field2":"Success","field3":0,"field4":1.0}" This made me lose some hair recently because of a bad implementation of an external webservice we used to query. I hope it to be of any help.

« previous php.notes (#217200) next »