note 91216 added to function.json-decode

From: Date: Sat, 30 May 2009 14:16:49 +0000
Subject: note 91216 added to function.json-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-156185@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 :) ===== 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; } } ---- Server IP: 208.69.120.35 Probable Submitter: 83.9.37.196 ---- Manual Page -- http://www.php.net/manual/en/function.json-decode.php Edit -- https://master.php.net/note/edit/91216 Del: integrated -- https://master.php.net/note/delete/91216/integrated Del: useless -- https://master.php.net/note/delete/91216/useless Del: bad code -- https://master.php.net/note/delete/91216/bad+code Del: spam -- https://master.php.net/note/delete/91216/spam Del: non-english -- https://master.php.net/note/delete/91216/non-english Del: in docs -- https://master.php.net/note/delete/91216/in+docs Del: other reasons-- https://master.php.net/note/delete/91216 Reject -- https://master.php.net/note/reject/91216 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156185) next »