The issue is I can't use any russian symbols in the response()->json()
method.
I've already tried the following code:
return response()->json(['users' => 'тест']);
and
return response()->json(['users' => mb_convert_encoding('тест', 'UTF-8')]);
and
return response()->json(
['users' => mb_convert_encoding('тест', 'UTF-8')])
->header('Content-Type', 'application/json; charset=utf-8');
I've checked the default encoding:
mb_detect_encoding('тест'); // returns 'UTF-8'
Also, all my files have been converter to UTF-8 without BOM. I've added the default character set to the .htaccess file(AddDefaultCharset utf-8
) as well.
But, I still get the wrong response like here:
{"users":"\u0442\u0435\u0441\u0442"}
{'users': 'тест'}
– Spellbinderu0442
is a unicode representation ofт
– Palaeojson_encode(['users', 'тест'], JSON_UNESCAPED_UNICODE)
– Spellbinderreturn response()->make(json_encode(['users' => 'тест'], JSON_UNESCAPED_UNICODE))->header('Content-Type', 'application/json; charset=utf-8');
has solved my issue. – Spellbinder