我有一個android應用程序,它連接到一個PHP腳本,然後從數據庫中提取數據並返回結果。除語言設置外,它都可以正常工作。我將語言設置爲dainsh和UTF-8,我可以想到的所有地方,並且當我將它發送到數據庫時,它是丹麥語,但返回值不是丹麥語。 下面是Android的設置語言安卓到php-mysqli
URL url = new URL(selectUrl);
HttpURLConnection httpUrlConncetion = (HttpURLConnection) url.openConnection();
httpUrlConncetion.setRequestMethod("POST");
httpUrlConncetion.setDoInput(true);
httpUrlConncetion.setConnectTimeout(10000);
httpUrlConncetion.setRequestProperty("Accept-Language", "da_DK");
httpUrlConncetion.setRequestProperty("Content-type", "application/json");
httpUrlConncetion.connect();
String line = "";
StringBuilder sb = new StringBuilder();
int Httpresult = httpUrlConncetion.getResponseCode();
Log.d(TAG, httpUrlConncetion.getResponseMessage().toString());
if (Httpresult == HttpURLConnection.HTTP_OK) {
InputStream inputStream = httpUrlConncetion.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
while ((line = reader.readLine()) != null) {
sb.append(line);
list.add(line);
}
result=sb.toString();
for(int i=0;i<list.size();i++){
Log.d(TAG, "min nye list" + list.get(i) + "\n");
}
我的PHP腳本調用和logcat的說
是, 「minegen」: 「N \ u00f8gler」}這就是問題所在。它應該是丹麥的「nøgler」。 的PHP已經這樣設置在連接文件到數據庫: 「mysqli_set_charset($ CON,‘UTF-8’);
和mysqli的數據庫已被設置爲丹麥語 - 這樣
所以我缺少什麼? 檢查時,任何幫助,將不勝感激:)
我認爲這不是mysqli,而是PHP編碼。嘗試設置mb_internal_encoding(「UTF-8」); – vishwakarma09
這看起來像一個逃脫的Unicode字符。嘗試'json_encode'上的'JSON_UNESCAPED_UNICODE'標誌。 http://php.net/json_encode –