class JsonDecode

Decodes JSON data

@author Sander Coolen <sander@jibber.nl>

Hierarchy

Expanded class hierarchy of JsonDecode

File

drupal/core/vendor/symfony/serializer/Symfony/Component/Serializer/Encoder/JsonDecode.php, line 19

Namespace

Symfony\Component\Serializer\Encoder
View source
class JsonDecode implements DecoderInterface {
  private $associative;
  private $recursionDepth;
  private $lastError = JSON_ERROR_NONE;
  public function __construct($associative = false, $depth = 512) {
    $this->associative = $associative;
    $this->recursionDepth = $depth;
  }

  /**
   * Returns the last decoding error (if any)
   *
   * @return integer
   *
   * @see http://php.net/manual/en/function.json-last-error.php json_last_error
   */
  public function getLastError() {
    return $this->lastError;
  }

  /**
   * Decodes a JSON string into PHP data
   *
   * @param string $data JSON
   *
   * @return mixed
   */
  public function decode($data, $format) {
    $decodedData = json_decode($data, $this->associative, $this->recursionDepth);
    $this->lastError = json_last_error();
    return $decodedData;
  }

  /**
   * {@inheritdoc}
   */
  public function supportsDecoding($format) {
    return JsonEncoder::FORMAT === $format;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JsonDecode::$associative private property
JsonDecode::$lastError private property
JsonDecode::$recursionDepth private property
JsonDecode::decode public function Decodes a JSON string into PHP data Overrides DecoderInterface::decode
JsonDecode::getLastError public function Returns the last decoding error (if any)
JsonDecode::supportsDecoding public function Checks whether the serializer can decode from given format Overrides DecoderInterface::supportsDecoding
JsonDecode::__construct public function