我正在寫一個android應用程序,我想查詢一個數據庫並用json_encode得到結果。 所以我有這個DB:json_encode,utf8和希臘字符
CREATE DATABASE `my_db` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
我用utf8的,因爲我想存儲希臘字符。所有表都有utf8_general_ci排序規則。
最後我有這個php服務,我用它來查詢我的分貝。
<?php
$host = "localhost";
$username = "root";
$password = "password";
$dbname = "my_db";
$con = mysql_connect($host,$username,$password) or die ('Error connecting to mysql');
mysql_query("SET character_set_results=utf8", $con);
mysql_query("SET NAMES 'utf8'", $con);
mysql_select_db($dbname,$con);
$query = "SELECT * from patients";
$result = mysql_query($query,$con);
while($e=mysql_fetch_assoc($result))
$output[]=$e;
print(json_encode($output));
mysql_close($con);
?>
的問題是,在輸出我不明白希臘字符。相反,我得到這樣的:
[{"patient_id":"2","email":"[email protected]","password":"password2","firstname":"\u03a7\u03a1\u0397\u03a3\u03a4\u039f\u03a3","lastname":"\u039c\u03a0\u0391\u0396\u0399\u03a9\u03a4\u0397\u03a3","birth":"1989-11-11","mobile":"6941212121","tameio":"\u039f\u0393\u0391"}]
如果您在客戶端使用json解碼(如JavaScript中的JSON.parse或php中的json_decode),它將解碼unicode轉義字符。 – jcubic
[php-json輸出web服務問題與utf-8字符(希臘語)]可能的重複](http://stackoverflow.com/questions/6397534/php-json-output-web-service-problem-with-utf- 8個字符和希臘)。您可能還想看看我的答案[度'°'字符不顯示在php json \ _encode函數,如何顯示此?](http://stackoverflow.com/questions/15964967/degree-character-不顯示在php-json-encode-function-how-to-display) – PleaseStand