Our basic solution is to transcode Chinese on the server side before the conversion, such as the JSON function or the hexadecimal conversion, and then convert the client accordingly, we still need to find a faster way, or it is best to use the JSON extension of PHP to directly support Chinese characters.
Today, I tested the built-in JSON function in PHP 5.2. JSON is mainly used for the data exchange format during Remote Access in Ajax, it can be said that it is a lightweight data exchange format used to replace the XML format in Ajax. The potential is not to be underestimated, because Google Maps is a typical example of using JSON without XML.
- Describes in detail the conversion of JSON serialization.
- The author provides detailed instructions on the Json getting started document.
- A full description of the JSON history
- Comparison between JSON and XML
- Details about the number of elements in JSON format that the server code will generate
For more information about JSON, see here for more articles. For more information about format definition, refer to the official JSON website. For more information about JSON, see Google.
- <?Php
- // Object
- Class JsonTest {
- Var $Id=1;
- Var $Name='Heiyeluren';
- Var $Gender=Male';
- }
- $Obj=NewJsonTest;
- Echo json_encode ($ obj )."<Br />";
-
- // Numeric index array
- $Arr1=Array(1, 'heiyeluren', 'male ');
- Echo json_encode ($ arr1 )."<Br />";
-
- // Associate the Index Array
- $Arr2=Array("Id" =>1, "name" =>'Heiyeluren', "gender" =>Male ');
- Echo json_encode ($ arr2 )."<Br />";
-
- // Multi-dimensional numeric index array
- $Arr3=Array(Array (1, 'heiyeluren', 'male'), array (1, 'heiyeluren', 'male '));
- Echo json_encode ($ arr3 )."<Br />";
-
- // Associate the Index Array
- $Arr4=Array(Array ("id" =>1, "name" =>'Heiyeluren', "gender" =>'Male'), array ("id" =>1, "name" =>'Heiyeluren', "gender" =>Male '));
- Echo json_encode ($ arr4 )."<Br />";
- ?>
-
-
-
- Browser output:
-
-
- {"Id": 1, "name": "heiyeluren", "gender ":""}
- [1, "heiyeluren", ""]
- {"Id": 1, "name": "heiyeluren", "gender ":""}
- [[1, "heiyeluren", ""], [1, "heiyeluren", ""]
- [{"Id": 1, "name": "heiyeluren", "gender": "" },{ "id": 1, "name": "heiyeluren ", "gender": ""}]
According to the JSON function definition, we can find the following features:
1. Pure Digital indexes are stored in arrays recognized by JavaScript.
2. The associated index array is constructed in the form of a JavaScript Object.
3. Multi-dimensional associated indexes are JavaScript arrays in the periphery, and the index arrays in the middle are objects.
4. Chinese cannot be recognized. All Chinese strings are displayed as blank