Json_encode, json_decode and UTF8

All,

I am making a JSON request to a web server using PHP and returning a JSON response in a variable. The JSON response will have many keys and values. The JSON response that I get from the server contains special characters in it. Therefore, I use the following operator to convert it to UTF8, decode JSON and use it as an array for display in the user interface.

$response = json_decode(utf8_encode($jsonresponse));

Now I have to pass the same value to the server in the JSON request to do something. However, when I transmit

$jsonrequest = json_encode(utf8_encode($request));

to the server, it does not work.

The following code succeeds in reading special characters and displaying it in the user interface. But it crashes if I need to pass the utf8_encode value to the server.

Current current round-trip code:

$requestdata  = json_encode($request);
$jsonresponse = //Do something to get from server;
$response = json_decode(utf8_encode($jsonresponse));

, , json ?

+3
5

JSON, , . , UTF8, JSON .

JSON UTF-8. UTF-8; .

:

$response = json_decode(utf8_encode($jsonresponse));

:

$response = json_decode($jsonresponse); //already UTF-8!
+6

php-:

$sql = "SET NAMES ‘utf8′";
mysql_query($sql, $link);
+3

?

$jsonrequest = utf8_encode(json_encode($request));

utf8_encode

+1

UTF-8, , - . , .

, ?

+1

ZF, utf-8 AJAX, , uft8_encode utf8_decode .

< meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8" / >

doctype

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" " http://www.w3.org/TR/html4/strict.dtd" >

?

0

Source: https://habr.com/ru/post/1758054/


All Articles