Swift Php Json汉字

时间:2015-02-23 10:35:03

标签: php json swift

我的数据库中有英文和中文字符,但是当我用JSON检索时,汉字不起作用。结果是"?"。有人可以帮帮我吗?

<?php

header('Content-Type: text/html; charset=utf-8');
/* include db.config.php */
include_once("config.php");
// Get user id
$id = isset($_GET['username']) ? mysql_real_escape_string($_GET['username']) : “”;

if(empty($id)){
    $data = array ("result" => 0, "message" => 'Wrong user id');
} else {
// get user data
$sql = mysql_query("SELECT username, gender, location, birthday, mobilephone, signature FROM users WHERE username='$id'");

$data = array ();

 while ($row = mysql_fetch_array($sql, MYSQL_ASSOC)) {
        $row_array['username'] = $row['username'];
        $row_array['gender'] = $row['gender'];
        $row_array['location'] = $row['location'];
        $row_array['birthday'] = $row['birthday'];
        $row_array['mobilephone'] = $row['mobilephone'];
        $row_array['signature'] = $row['signature'];
        //push the values in the array
        array_push($data,$row_array);
 }
 echo json_encode($data);

mysql_close($conn);
/* JSON Response */
}
?>

1 个答案:

答案 0 :(得分:1)

确保您的表字段排序规则设置为utf8-general-ci。打开你的桌子 - &gt;结构 - &gt;在这里检查一下。如果不是,请编辑该字段并进行更改。现在添加新条目并检查。