In the interface return data, we often return JSON or XML format, PHP JSON serialization function Json_encode very useful, but the default will be encoded in Chinese ASCII code (note that many people think this is garbled, in fact, not), especially when debugging interface, See a large number of ASCII code, a face confused, do not know is right is wrong:
Code:
<?PHPclassa{ Public $num; Public $name; function__construct ($_num,$_name) { $this->num=$_num; $this->name=$_name; }}$class=NewA (' A001 ', ' Zhang San ');//Serialization of Json_encode$json=json_encode ($class);Echo $json;
Results:
Doesn't look very uncomfortable,
The solution is also very simple, online search, PHP5.4 version, has been added to the JSON option: Json_unescaped_unicode. With this option, the Chinese is not automatically encoded.
Try it:
classa{ Public $num; Public $name; function__construct ($_num,$_name) { $this->num=$_num; $this->name=$_name; }}$class=NewA (' A001 ', ' Zhang San ');//Serialization of Json_encode$json=json_encode ($class,Json_unescaped_unicode);//plus Json_unescaped_unicode .Echo $json;
Results:
Coding display problems in Chinese after JSON serialization in PHP