Q & A: The PHP server returns Json. We need to improve our programming ideas in the accumulation of experience, flexible use of the json_encode documentation to see, it can only encode the characters of the UTF-8. This problem is returned. we need to improve our programming ideas through continuous experience and use them flexibly.
After looking at the json_encode document to know, it can only encode the characters of the UTF-8. This problem is how the returned characters are GB2312, and it is best to convert the entire array into a UTF-8. Search for the following code to solve the Json returned by the PHP server:
- Function encodeUTF8 ($ array)
- {
- Foreach ($ array as $ key =>$ Value)
- {
- If (! Is_array ($ value ))
- {
- $ Array [$ key] = mb_convert
_ Encoding ($ value, "UTF-8", "GBK ");
- }
- Else
- {
- EncodeUTF8 ($ array [$ key]);
- }
- }
- Return $ array;
- }
Each time a result is returned:
- echo '{"total":"'.$rscount.'
","results":'.json_encode
(encodeUTF8($result)).'}';
The above code is the specific solution to the Json problem returned by the PHP server.
After coding, let's see the json_encode document to know that it can only encode characters of the UTF-8. This problem is returned...