gpt4 book ai didi

java - HttpResponse 中的阿拉伯语格式错误

转载 作者:行者123 更新时间:2023-11-30 04:01:13 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Parsing an UTF-8 Encodded XML file

我正在解析一个 UTF-8 编码的 XML 文件,其中包含一些阿拉伯字符,除了不显示阿拉伯字符外,其他一切都正常工作,一些奇怪的字符显示如下:

ÙرÙÙ

这是正在解析的 XML“http://212.12.165.44:7201/UniNews121.xml”文件的链接

下面是代码

        public String getXmlFromUrl(String url) {

try {
return new AsyncTask<String, Void, String>() {
@Override
protected String doInBackground(String... params) {
//String xml = null;
try {

DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET,"UTF-8");
HttpGet httpPost = new HttpGet(params[0]);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
xml = new String(EntityUtils.toString(httpEntity).getBytes(),"UTF-8");

} catch (Exception e) {
e.printStackTrace();
}

//just to remove the BOM Element
xml=xml.substring(3);

//Here am printing the xml and the arabic chars are malformed
Log.i("DEMO", xml);
return xml;

}
}.execute(url).get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return xml;
}

请注意,没有发生任何错误,一切正常,只是阿拉伯字符格式不正确。

非常感谢您的帮助,但请在您的回答中具体说明

26 4 0
文章推荐: android - 如何在StartTrackingTouch the seekbar上隐藏软键盘
文章推荐: android -
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com