note 91216 modified in function.json-decode by danbrown

From: Date: Sat, 30 May 2009 14:17:44 +0000
Subject: note 91216 modified in function.json-decode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156186@lists.php.net to get a copy of this message
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; } } ?> --was-- 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 :) ===== 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; } } http://php.net/manual/en/function.json-decode.php

« previous php.notes (#156186) next »