You are here

function _spaces_json_decode in Spaces 6.3

From http://www.php.net/manual/en/function.json-decode.php#91216 with modifications for consistency with output of json_decode().

Original author: walidator.info 2009.

1 call to _spaces_json_decode()
spaces_json_decode in ./spaces.module
Compatibility wrapper around json_decode().

File

./spaces.module, line 977

Code

function _spaces_json_decode($json) {
  $comment = false;
  $out = '$x = ';
  for ($i = 0; $i < strlen($json); $i++) {
    if (!$comment) {
      switch ($json[$i]) {
        case '{':
          $out .= ' (object) array(';
          break;
        case '}':
          $out .= ')';
          break;
        case '[':
          $out .= ' array(';
          break;
        case ']':
          $out .= ')';
          break;
        case ':':
          $out .= '=>';
          break;
        default:
          $out .= $json[$i];
          break;
      }
    }
    else {
      $out .= $json[$i];
    }
    if ($json[$i] == '"') {
      $comment = !$comment;
    }
  }
  eval($out . ';');
  return $x;
}