'Wrong user id'); } else {-6ren">
gpt4 book ai didi

php - Swift Php Json 汉字

转载 作者:行者123 更新时间:2023-11-30 10:18:35 26 4
gpt4 key购买 nike

我的数据库中有英文和中文字符,但是当我在 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 */
}
?>

最佳答案

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

关于php - Swift Php Json 汉字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28671729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com