note 87776 added to function.json-decode
| From: | jan at hooda dot de | Date: | Sun, 21 Dec 2008 04:20:40 +0000 |
| Subject: | note 87776 added to function.json-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148402@lists.php.net to get a copy of this message | ||
This function will convert a "normal" json to an array.
<?php
function json_code ($json) {
//remove curly brackets to beware from regex errors
$json = substr($json, strpos($json,'{')+1, strlen($json));
$json = substr($json, 0, strrpos($json,'}'));
$json = preg_replace('/(^|,)([\\s\\t]*)([^:]*) (([\\s\\t]*)):(([\\s\\t]*))/s',
'$1"$3"$4:', trim($json));
return json_decode('{'.$json.'}', true);
}
$json_data = '{
a: 1,
b: 245,
c with whitespaces: "test me",
d: "function () { echo \"test\" }",
e: 5.66
}';
$jarr = json_code($json_data);
?>
----
Server IP: 212.124.37.9
Probable Submitter: 84.153.72.209
----
Manual Page -- http://www.php.net/manual/en/function.json-decode.php
Edit -- https://master.php.net/note/edit/87776
Del: integrated -- https://master.php.net/note/delete/87776/integrated
Del: useless -- https://master.php.net/note/delete/87776/useless
Del: bad code -- https://master.php.net/note/delete/87776/bad+code
Del: spam -- https://master.php.net/note/delete/87776/spam
Del: non-english -- https://master.php.net/note/delete/87776/non-english
Del: in docs -- https://master.php.net/note/delete/87776/in+docs
Del: other reasons-- https://master.php.net/note/delete/87776
Reject -- https://master.php.net/note/reject/87776
Search -- https://master.php.net/manage/user-notes.php