You are here

static function context_reaction_block::_json_decode in Context 6

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 context_reaction_block::_json_decode()
context_reaction_block::json_decode in plugins/context_reaction_block.inc
Compatibility wrapper around json_decode().

File

plugins/context_reaction_block.inc, line 524

Class

context_reaction_block
Expose blocks as context reactions.

Code

static function _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;
}