我使用JSON获取查询结果,但是使用特殊字符,它显示的是NULL而不是正确的结果。我已尝试array_map('utf8_encode')
,但我仍然遇到同样的错误。
代码:
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["reserves"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
array_map('utf8_encode', $product);
$product["id_reserve"] = $row["id_r"];
$product["description"] = $row["d_reserve"];
// push single product into final response array
array_push($response["reserves"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
答案 0 :(得分:1)
(代表OP发布)。
要设置数组值utf-8,必须将函数utf8_encode放在$ row之前。结果是:
$product["description"] = utf8_encode($row["d_reserve"]);