PHP Json_encode prompt in Chinese always return "\u767b\u5f55\u6210\u529f\uff01" solution

Source: Internet
Author: User

Recently in the practice of using PHP to write some simple interface, but in the returned message, if there is Chinese, after testing always return:

{"ResultCode": $, "message": "\u767b\u5f55\u6210\u529f\uff01", "data": {"user_id": "", "User_phone": " 13918145846 "," user_name ":null," user_sex ":null," User_password ":" 123456 "," User_header " : Null}}

Here's what I wrote:

$row=mysql_num_rows($result); if($row= = 1){        $array=Array();  while($row=Mysql_fetch_array($result)){            $array["user_id"] =$row["user_id"]; $array["user_phone"] =$row["User_phone"]; $array["user_name"] =$row["User_name"]; $array["user_sex"] =$row["User_sex"]; $array["user_password"] =$row["User_password"]; $array["user_header"] =$row["User_header"]; }        //returns the above array in JSON format        $json= Json_encode (Array(            "ResultCode" =>200, "message" and "=" Login Successful! "," Data "=$array        )); Echo($json); }Else{        $json= Json_encode (Array(            "ResultCode" =>500, "message" = "Login failed!" "        )); Echo($json); }

Before the test, always show this one?

Through the online search data and traffic, learned that php5.4 JSON added an option: Json_unescaped_unicode, so the name Incredibles, that is, JSON do not encode UNICODE.

As long as we are in Json_encode (Array (),Json_unescaped_unicode), we can output normal Chinese in the code:

$json = json_encode (array(            "ResultCode" =>200,            "message" + = "Login Successful! ",            " data "=$array        ),json_unescaped_unicode);         Echo ($json);

See test results:

This is a few words difficult to spell!!!!

PHP Json_encode prompt in Chinese always return "\u767b\u5f55\u6210\u529f\uff01" solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.