public function JsonEncode::encode in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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\EncoderCode
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;
}