note 110768 added to function.json-decode
| From: | sskaje at gmail dot com | Date: | Thu, 06 Dec 2012 02:36:36 +0000 |
| Subject: | note 110768 added to function.json-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-192279@lists.php.net to get a copy of this message | ||
A fix to colin.mollenhour.com 21-Jan-2010 02:51 http://www.php.net/manual/en/function.json-decode.php#95782
<?php
function json_decode_nice($json, $assoc = FALSE){
$json = str_replace(array("\n","\r"),"",$json);
$json =
preg_replace('/([{,]+)(\s*)([^"]+?)\s*:/','$1"$3":',$json);
return json_decode($json,$assoc);
}
?>
Old regexp failed when json like
{aaa:[{a:1},{a:2}]}
----
Server IP: 69.147.83.199
Probable Submitter: 72.52.91.2 (proxied: 106.187.43.166)
----
Manual Page -- http://php.net/manual/en/function.json-decode.php
Edit -- https://master.php.net/note/edit/110768
Del: integrated -- https://master.php.net/note/delete/110768/integrated
Del: useless -- https://master.php.net/note/delete/110768/useless
Del: bad code -- https://master.php.net/note/delete/110768/bad+code
Del: spam -- https://master.php.net/note/delete/110768/spam
Del: non-english -- https://master.php.net/note/delete/110768/non-english
Del: in docs -- https://master.php.net/note/delete/110768/in+docs
Del: other reasons-- https://master.php.net/note/delete/110768
Reject -- https://master.php.net/note/reject/110768
Search -- https://master.php.net/manage/user-notes.php