note 91656 added to function.json-decode
| From: | premiersullivan at gmail dot com | Date: | Sun, 21 Jun 2009 23:14:41 +0000 |
| Subject: | note 91656 added to function.json-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-157205@lists.php.net to get a copy of this message | ||
This function will remove trailing commas and encode in utf8, which might solve many people's
problems. Someone might want to expand it to also change single quotes to double quotes, and fix
other kinds of json breakage.
<?php
function mjson_decode($json)
{
return json_decode(removeTrailingCommas(utf8_encode($json)));
}
function removeTrailingCommas($json)
{
$json=preg_replace('/,\s*([\]}])/m', '$1', $json);
return $json;
}
?>
----
Server IP: 209.41.74.194
Probable Submitter: 24.130.20.121
----
Manual Page -- http://www.php.net/manual/en/function.json-decode.php
Edit -- https://master.php.net/note/edit/91656
Del: integrated -- https://master.php.net/note/delete/91656/integrated
Del: useless -- https://master.php.net/note/delete/91656/useless
Del: bad code -- https://master.php.net/note/delete/91656/bad+code
Del: spam -- https://master.php.net/note/delete/91656/spam
Del: non-english -- https://master.php.net/note/delete/91656/non-english
Del: in docs -- https://master.php.net/note/delete/91656/in+docs
Del: other reasons-- https://master.php.net/note/delete/91656
Reject -- https://master.php.net/note/reject/91656
Search -- https://master.php.net/manage/user-notes.php