目前,我使用 PHP 3.5 从 SQL Server 获取数据,我将以 Json 格式返回。但是在我的数据库中,我有不同语言的数据,如中文,泰语,日语,韩语等,当我返回以这种格式显示的数据时: ??????
如何以原始格式显示数据? 下面是我的代码:
$query = "SELECT
[name]
,[venue]
FROM tablename
WHERE id = '2'";
/**********************************************/
//Just for the Purpose of Count Number of Rows
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
/******************************/
#Query the database to get the user details.
$res = sqlsrv_query($conn, $query, $params, $options);
$arr = array();
#If no data was returned, check for any SQL errors
if ($res == false)
{
echo 'Query not Executed : '. die(print_r(sqlsrv_errors(), TRUE));
}
else
{
while($obj = sqlsrv_fetch_array($res, SQLSRV_FETCH_ASSOC))
{
$arr[] = array(
"name" => $obj['name'],
"venue" => $obj['venue']
);
}
}
header('Content-type: application/json; charset=utf-8');
#Output the JSON data
echo json_encode($arr);
exit();
sqlsrv_free_stmt($res); // Closes a statement. Frees all resources associated.
sqlsrv_close($conn); // Closes a connection. Frees all resources associated.
答案 0 :(得分:1)
你有没有试过下面的代码?
echo json_encode($arr,JSON_UNESCAPED_UNICODE);