Found a solution online:
Copy the code The code is as follows:
/* Processing json_encode Chinese garbled characters*/
$data = array ('game' => 'The Kingdom of Ice and Fire ', 'name' => 'Thorn Spirit', 'country' => 'Frost Country', 'level' => 45 );
echo json_encode ( $data );
echo "
" ;
$newData = array ();
foreach ( $data as $key => $value ) {
$newData [$key] = urlencode ( $value );
}
echo urldecode ( json_encode ( $newData ) ) ;
?>
Later, I asked others for advice. Base64 encoding can also be used, but base64 encoding cannot be placed in the URL. Baidu explained this:
Standard Base64 is not suitable for transmission directly in the URL because The URL encoder will convert the "/" and "+" characters in standard Base64 into a form such as "%XX", and these "%" characters need to be converted when they are stored in the database, because ANSI SQL has Use the "%" sign as a wildcard character.
However, my data is sent via POST and is not in the HTTP head, but in the message-body, so it is not affected.
json_encode can only accept data in utf-8 format
urlencode base64_encode can only accept string type parameters, so the entire array cannot be encoded.
The above introduces json_encode PHP learning notes_Encoding json_encode Chinese is not displayed, including json_encode content. I hope it will be helpful to friends who are interested in PHP tutorials.