Chinese garbled characters returned by the server

Source: Internet
Author: User
The server returns Chinese garbled characters. the server writes the code in php and displays the Chinese garbled characters in the browser. the Chinese characters received by android are garbled characters, including database encoding, database tables, fields, and database connections, the apache server code is UTF-8, which is displayed in the browser: the content field is Chinese in the database {"posts": [{"post server returns Chinese garbled characters
The server side is written in php and displays garbled characters in the browser. Chinese characters received by android are garbled characters. database encoding, database tables, fields, database connections, and apache server encoding are UTF-8,

The result is displayed in the browser: the content field is Chinese in the database.
{"Posts": [{"post": {"ID": "1", "Account_ID": "A220", "Receiver_ID": "B220", "Consumption_Amount ": "100", "Content": "\ u9910 \ u5385 \ u6d88 \ u8d39", "Time": "2013-08-20" }}, {"post": {"ID ": "3", "Account_ID": "A220", "Receiver_ID": "B221", "Consumption_Amount": "10", "Content ": "\ u516c \ u4ea4 \ u8f66 \ u6d88 \ u8d39", "Time": "2013-08-21" },{ "post": {"ID": "4 ", "Account_ID": "A220", "Receiver_ID": "B222", "Consumption_Amount": "500", "Content": "\ u8d2d \ u00009 \ u6d88 \ u8d39 ", "Time": "2013-08-22" }}, {"post": {"ID": "5", "Account_ID": "A220", "Receiver_ID": "B223 ", "Consumption_Amount": "50", "Content": "\ u516c \ u4ea4 \ u8f66 \ u6d88 \ u8d39", "Time": "2013-08-08" }}, {"post ": {"ID": "6", "Account_ID": "A220", "Receiver_ID": "B224", "Consumption_Amount": "100", "Content ": "\ u624b \ u673a \ u5145 \ u503c", "Time": "2013-08-10" }}, {"post": {"ID": "7", "Account_ID ": "A220", "Receiver_ID": "B225", "Consumption_Amount": "1000", "Content": "\ u8f6c \ u8d26", "Time ": "2013-08-06" }}]}
Server code:




Header ("Content-Type: text/html; charset = UTF-8 ");
$ Format = 'json'; // xml is the default
/* Connect to the database */
$ Link = mysql_connect ('localhost', 'root', '000000') or die ('cannot connect to the db ');
// Mysql_query ("set names UTF8 ");
Mysql_select_db ('Citi _ db', $ link) or die ('could not select the db ');
Mysql_query ("set names utf8 ");
Mysql_query ("SET CHARACTER_SET_CLIENT = utf8 ");
Mysql_query ("SET CHARACTER_SET_RESULTS = utf8 ");
$ Query = "SELECT * FROM 'consumption _ detail' WHERE 'account _ id' = 'a220 '";
$ Result = mysql_query ($ query, $ link) or die ('errant query: '. $ query );

$ Posts = array ();
If (mysql_num_rows ($ result )){
While ($ post = mysql_fetch_assoc ($ result )){
$ Posts [] = array ('post' => $ post );
}
}

/* Json format */
If ($ format = 'json '){
Header ("Content-type: text/html; charset = UTF-8 ");
Echo json_encode (array ('posts' => $ posts ));

}

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.