note 91216 deleted from function.json-decode by googleguy
| From: | googleguy@php.net | Date: | Fri, 30 Nov 2012 05:38:43 +0000 |
| Subject: | note 91216 deleted from function.json-decode by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192210@lists.php.net to get a copy of this message | ||
Note Submitter: www at walidator dot info
----
Here's a small function to decode JSON. It might not work on all data, but it works fine on
something like this:
$json_data = '{"response": {
"Text":"Hello there"
},
"Details": null, "Status": 200}
';
===== CUt HERE :) =====
<?php
if ( !function_exists('json_decode') ){
function json_decode($json)
{
// Author: walidator.info 2009
$comment = false;
$out = '$x=';
for ($i=0; $i<strlen($json); $i++)
{
if (!$comment)
{
if ($json[$i] == '{') $out .= ' array(';
else if ($json[$i] == '}') $out .= ')';
else if ($json[$i] == ':') $out .= '=>';
else $out .= $json[$i];
}
else $out .= $json[$i];
if ($json[$i] == '"') $comment = !$comment;
}
eval($out . ';');
return $x;
}
}
?>