You are here

function JSON::serialize in Drupal Most Popular 7

Serialize

Serialize a PHP OBJECT or an ARRAY into JSON notation.

param mixed $obj Object or array to serialize return string JSON.

1 call to JSON::serialize()
JSON::_serialize in modules/mostpopular_disqus/disqusapi/json.php
Internal Serializer

File

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

Class

JSON
JSON

Code

function serialize($obj) {
  if (is_object($obj)) {
    $e = get_object_vars($obj);

    /* bug reported by Ben Rowe */

    /* Adding default empty array if the */

    /* object doesn't have any property */
    $properties = array();
    foreach ($e as $k => $v) {
      $properties[] = $this
        ->_serialize($k, $v);
    }
    return "{" . implode(",", $properties) . "}";
  }
  else {
    if (is_array($obj)) {
      return $this
        ->_serialize('', $obj);
    }
  }
}