M
M
Mr_Romanov2016-11-15 19:25:58
symfony
Mr_Romanov, 2016-11-15 19:25:58

JsonResponse symfony how to use cyrillic?

when I use return new JsonResponse($data);
in the latest version of symphony, instead of Cyrillic, I get \u041f\u0430\u0448\u0430
as well as escaping slashes.
How do I write JSON_UNESCAPED_UNICODE and JSON_UNESCAPED_SLASHES for JsonResponse in symfony?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bears, 2016-11-15
@Mr_Romanov

In my opinion, there is only one constant that can be passed to setEncodingOptions

$response = new JsonResponse(['message' => 'Привет!']);
$response->setEncodingOptions(JSON_UNESCAPED_UNICODE);

return $response;

Z
ZardoZAntony, 2020-05-02
@ZardoZAntony

In this scenario, when there are slashes, Russian letters and tags, if not converted to UTF-8, I received
return new JsonResponse($data);

Malformed UTF-8 characters, possibly incorrectly encoded

So at least how I had to call like this
return new JsonResponse(mb_convert_encoding($data, 'UTF-8', 'UTF-8'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question