![](/img/trans.png)
[英]How to pass a value from android to php web service and retrieve it?
[英]How to send and retrieve data from web service using PHP and Android
我正在開發一個應用程序,在該應用程序中,我將從Web服務獲取數據並在Android移動設備中顯示。 但是問題是在獲取土耳其數據時,它無法正確顯示。
我已經在PHP中設置了utf-8
。 但是對於字符串Açık Öğretim
仍然獲得特殊字符符號,例如A?ık ?ğ
。
這是我的PHP代碼:
<?php
include("Netbrut_class.php");
header('Content-type: text/xml; charset: utf-8');
$webservice = new Netbrut;
$content='<?xml version="1.0" encoding="utf-8"?><salary_comparision>';
$education = $webservice->select_education();
for($i=0; $i<count($education); $i++){
$string = html_entity_decode($education[$i]['comparision_name'], ENT_QUOTES, "utf-8");
$content.="<education id='".$education[$i]['id']."'>".$string."</education>";
}
$content .='</salary_comparision>';
echo $content;
?>
我的Java代碼是/在這里,我只是為了測試而編寫Java代碼:
public class testing {
static String[] attributes;
public static void main(String[] args)
{
URL url;
try {
url = new URL("http://192.168.1.106/netBrut/webservices/testing.php");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection = (HttpURLConnection) url.openConnection();
java.io.InputStream is = connection.getInputStream();
InputStreamReader reader = new InputStreamReader(is, "utf-8");
StringWriter sw = new StringWriter();
char [] buffer = new char[1024 * 8];
int count ;
while( (count = reader.read(buffer)) != -1){
sw.write(buffer, 0, count);
}
System.out.println(sw.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
從Web服務返回XML是:
<?xml version="1.0" encoding="utf-8"?>
<salary_comparision>
<education id='128'>A?ık ?ğretim</education>//Check here
<education id='5'>Doktora</education>
<education id='3'>Master</education>
<education id='4'>MBA</education>
<education id='2'>?niversite</education>
</salary_comparision>
在PHP代碼中,只需更改以下幾行
$string = html_entity_decode($education[$i]['comparision_name'], ENT_QUOTES, "utf-8");
$content.="<education id='".$education[$i]['id']."'>".$string."</education>";
至
$string = $webservice->unhtmlspecialchars($education[$i]['comparision_name']);
$content.="<education id='".$education[$i]['id']."'>".$string."</education>";
請參閱htmlspecialchars
文檔 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.