Skip to content

Commit

Permalink
Fixed json_decode for PHP < 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
makotokw committed Sep 24, 2010
1 parent 52a9474 commit 0141a76
Show file tree
Hide file tree
Showing 5 changed files with 1,358 additions and 20 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -119,6 +119,11 @@ TODO
HISTORY
============

v0.3.1
----------------

* Uses the Services_JSON instead of json_decode when PHP < 5.2.0

v0.3
----------------

Expand Down
25 changes: 5 additions & 20 deletions lib/Twitter/Request.php
Expand Up @@ -134,26 +134,11 @@ public function postJSON($url, array $params = array(), $auth = false, $callback
}

// from http://php.net/manual/en/function.json-decode.php
if ( !function_exists('json_decode') ){
function json_decode($json)
if (!function_exists('json_decode')) {
if (!class_exists('Services_JSON')) require_once dirname(__FILE__).'/../vendor/Services_JSON/JSON.php';
function json_decode($content, $assoc=false)
{
// 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;
$json = new Services_JSON(($assoc) ? SERVICES_JSON_LOOSE_TYPE : 0);
return $json->decode($content);
}
}

0 comments on commit 0141a76

Please sign in to comment.