note 129887 added to function.json-encode
| From: | diagnose@gmail.com | Date: | Wed, 27 Nov 2024 03:13:30 +0000 |
| Subject: | note 129887 added to function.json-encode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221688@lists.php.net to get a copy of this message | ||
Beware of Trailing Backslashes!
The JSON specification *does not allow* trailing backslashes in strings. It will create a
JSON-encoded string without throwing an error, but this string will cause an error when parsed.
For example, the string "Example\" will cause the following error in JavaScript when
parsing:
JSON.parse: expected ',' or '}' after property value in object
This appears to be an oversight in the JSON specification and the only work-around appears to be
removing trailing slashes from all strings before encoding.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 79.135.105.182)
----
Manual Page -- https://php.net/manual/en/function.json-encode.php
Edit -- https://main.php.net/note/edit/129887
Del: integrated -- https://main.php.net/note/delete/129887/integrated
Del: useless -- https://main.php.net/note/delete/129887/useless
Del: bad code -- https://main.php.net/note/delete/129887/bad+code
Del: spam -- https://main.php.net/note/delete/129887/spam
Del: non-english -- https://main.php.net/note/delete/129887/non-english
Del: in docs -- https://main.php.net/note/delete/129887/in+docs
Del: other reasons-- https://main.php.net/note/delete/129887
Reject -- https://main.php.net/note/reject/129887
Search -- https://main.php.net/manage/user-notes.php