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