Bug #52502 [Opn->Bgs]: json_decode doesn't always work
| From: | rasmus@php.net | Date: | Sat, 31 Jul 2010 03:34:57 +0000 |
| Subject: | Bug #52502 [Opn->Bgs]: json_decode doesn't always work | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-152987@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52502&edit=1
ID: 52502
Updated by: rasmus@php.net
Reported by: zelnaga at gmail dot com
Summary: json_decode doesn't always work
-Status: Open
+Status: Bogus
Type: Bug
Package: *General Issues
Operating System: Windows 7
PHP Version: 5.3.3
Block user comment: N
New Comment:
PHP uses the reference implementation from json.org. json.org states
that a new-
line in json is written as \n and not a literal newline. If you can
convince
Douglas Crockford at json.org that this should be valid json, we will
fix it.
Otherwise, no chance.
Previous Comments:
------------------------------------------------------------------------
[2010-07-31 04:50:11] zelnaga at gmail dot com
Description:
------------
In particular, "{\"test\": [\"\n\"]}" doesn't give the correct
result.
Examples follow.
Test script:
---------------
<?php
$a = "{\"test\": [\"\n\"]}";
echo "$a\r\n";
var_dump(json_decode($a, true));
?>
Expected result:
----------------
I would expect an array to be output. ie.
array(1) {
["test"]=>
array(1) {
[0]=>
string(1) "
"
}
}
Certainly javascript has no problem with it:
<script
src="http://github.com/kvz/phpjs/raw/master/functions/strings/echo.js"></script>
<script
src="http://github.com/kvz/phpjs/raw/master/functions/var/var_dump.js"></script>
<script>
a = {"test": ["\n"]};
var_dump(a);
</script>
Actual result:
--------------
NULL
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52502&edit=1