我得到一个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);
(代表OP发布)
要设置数组值utf-8,函数utf8_encode必须放在$row之前。结果是:
$product["description"] = utf8_encode($row["d_reserve"]);