You are here

public function JsonEncode::encode in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/serializer/Encoder/JsonEncode.php \Symfony\Component\Serializer\Encoder\JsonEncode::encode()

Encodes PHP data to a JSON string.

Overrides EncoderInterface::encode

File

vendor/symfony/serializer/Encoder/JsonEncode.php, line 52

Class

JsonEncode
Encodes JSON data.

Namespace

Symfony\Component\Serializer\Encoder

Code

public function encode($data, $format, array $context = array()) {
  $context = $this
    ->resolveContext($context);
  $encodedJson = json_encode($data, $context['json_encode_options']);
  if (JSON_ERROR_NONE !== ($this->lastError = json_last_error())) {
    throw new UnexpectedValueException(JsonEncoder::getLastErrorMessage());
  }
  return $encodedJson;
}