Mssql 结果json_encode不返回任何 php pdo


Array
(
[0] => Array
(
[acctcode] => 631
[description] => Blood Transfussion Set, Blood Transfusion Set- ADULT
[pchrgqty] => 1.00
[pchrgup] => 17.00
[pcchrgamt] => 17.00
[patlast] => GUADA�A
[patfirst] => FRITZIE ELINE
[patmiddle] => DAYTEC
[patsuffix] => 
)
)

上面的 php 数组是print_r($result);的结果,现在这个数组将json_encoded如下:

echo json_encode($result, JSON_UNESCAPED_UNICODE);

我正在对此进行编码,因为它用于 ajax 请求。现在在回声部分,它没有返回任何内容。我不知道为什么会发生这种情况,但我的猜测是因为“Ñ”[patlast] => GUADA�A中,显示为。我在选择MSSQL DATABASE中得到这个结果集。

如何在 MSSQL 中处理此结果集并能够返回正确的数据。

我在这里找到了适合我项目的最佳解决方案

使用以下代码:

// Create an empty array for the encoded resultset
$rows = array();
// Loop over the db resultset and put encoded values into $rows
while($row = mysql_fetch_assoc($result)) {
$rows[] = array_map('utf8_encode', $row);
}
// Output $rows
echo json_encode($rows);

答案给了我的用户Kemo

最新更新