You are here

function JSON::_unserialize in Drupal Most Popular 7

UnSerialize

Transform an JSON text into a PHP object and return it. @access private

Parameters

string $text JSON text: @return mixed PHP Object, array or false.

1 call to JSON::_unserialize()
JSON::unserialize in modules/mostpopular_disqus/disqusapi/json.php
UnSerialize

File

modules/mostpopular_disqus/disqusapi/json.php, line 127

Class

JSON
JSON

Code

function _unserialize($text) {
  $ret = new stdClass();
  while ($f = $this
    ->getNextToken($text, $i, $type)) {
    switch ($type) {
      case IN_ARRAY:
        $tmp = $this
          ->_unserializeArray($text);
        $ret = $tmp[0];
        break;
      case IN_OBJECT:
        $g = 0;
        do {
          $varName = $this
            ->getNextToken($f, $g, $xType);
          if ($xType != IN_STRING) {
            return false;

            /* error parsing */
          }
          $this
            ->getNextToken($f, $g, $xType);
          if ($xType != IN_ASSIGN) {
            return false;
          }
          $value = $this
            ->getNextToken($f, $g, $xType);
          if ($xType == IN_OBJECT) {
            $ret->{$varName} = $this
              ->unserialize("{" . $value . "}");
            $g--;
          }
          else {
            if ($xType == IN_ARRAY) {
              $ret->{$varName} = $this
                ->_unserializeArray($value);
              $g--;
            }
            else {
              $ret->{$varName} = $value;
            }
          }
          $this
            ->getNextToken($f, $g, $xType);
        } while ($xType == IN_ENDSTMT);
        break;
      default:
        $this->error = true;
        break 2;
    }
  }
  return $ret;
}