2013-02-27 48 views
1

我的XML響應正常顯示是一些匈牙利的字符不會在android系統

<name> DPD futár </name>

我的XML解析代碼

 SAXParserFactory _saxFactory = SAXParserFactory.newInstance(); 
     SAXParser _saxParser = _saxFactory.newSAXParser(); 
     XMLReader _xmlReader = _saxParser.getXMLReader(); 
     _shippingMethodList = new ArrayList<ShippingMethodItem>(); 
     ShippingMethodParser _cartLoginParser = new ShippingMethodParser(
       _shippingMethodList); 
     _xmlReader.setContentHandler(_cartLoginParser); 
     InputSource is = new InputSource(); 
     is.setEncoding("ISO-8859-1"); 
     is.setCharacterStream(new StringReader(response)); 
     _xmlReader.parse(is); 

但我得到了下面的字符串我名稱變量。

DPDfutár

我也嘗試用

is.setEncoding("UTF-8"); 

,但沒有得到成功。任何人都可以幫我解決這個問題嗎?

+0

可能幫助you.http://stackoverflow.com/questions/4259128/how-can-i-create-a-multilingual-android-application – 2013-02-27 12:48:44

回答

1

試試這個

InputSource in = new InputSource(new InputStreamReader(url.openStream(),"ISO-8859-1")); 
0

匈牙利語數據不應該使用ISO-8859-1(拉丁語1)編碼,因爲它不包含國家字符,如ő。字母á也是葡萄牙語和西班牙字母的一部分,並且都由拉丁語1支持,但在匈牙利語中,只有拉丁語2(ISO-8859-2)可以使用。但是,您應該儘可能使用unicode編碼。

首先我會檢查收到的數據是否正確編碼,因爲當您將字符串編碼爲unicode時也可能發生錯誤。您提供的示例是典型的編碼錯誤。也許你試圖將UTF-8編碼爲UTF-8,這是錯誤的。

+0

不是成功轉換後\t is.setEncoding(「ISO-8859-2」); – 2013-02-27 13:07:28

+0

我認爲你以適當的UTF-8編碼接收你的數據,但不知何故強制解析器重新編碼它。你不需要那個。按原樣處理XML。如果SAX無法觸摸原始編碼就無法完成,那麼請嘗試Pull Parser,無論如何它的運行速度都會更快。 – 2013-02-27 13:10:55