看板 AndroidDev 關於我們 聯絡資訊
想請教一下大家在處理BIG5編碼的網頁時都是如 何處理呢? 因為EntityUtils 似乎沒有支援BIG5..所以小弟的程 式是這樣處理的(如下) 可是發現再遇到一些特殊字元如 " > 的時候都會 變的怪怪的~ 感謝指教!! public static String GET2getWEB(String linkString) { byte[] byteResponse = null;//FOR BIG 5 String strRet = null; try { HttpGet GET2LINK = new HttpGet (linkString); /* 取得HTTP response */ HttpResponse httpResponse = new DefaultHttpClient() .execute(GET2LINK); HttpEntity entity = httpResponse.getEntity(); /* 取出回應字串 */// strRet = EntityUtils.toString(entity,HTTP.UTF_8); //for big5 編碼 if (entity != null && HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()) { //strRet = EntityUtils.toString(entity,HTTP.ISO_8859_1); //strRet = EntityUtils.toString(entity); byteResponse = EntityUtils.toByteArray(entity); strRet = EncodingUtils.getString(byteResponse, "big5"); } } catch (Exception e) { e.printStackTrace(); } return strRet; }//end of post2getWEB -- posted from android bbs reader on my HTC Sensation XE with Beats Audio Z715e https://market.android.com/details?id=com.bbs.reader -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 42.72.204.134 ※ 編輯: Magicx 來自: 114.34.226.28 (01/16 00:50)
tericky:為什麼回應字串要轉編碼兩次??? 01/16 21:48
tericky:既然已經知道source是big5,要轉成UTF-8,直接 01/16 21:49
tericky:strRet = new String( 01/16 21:51
tericky: EntityUtils.toString(response.getEntity()) 01/16 21:52
tericky: .getBytes("ISO-8859-1"), "UTF-8") 01/16 21:52
tericky:至於>、<、&這種特殊符號,除了tag以外,都要自己轉換格式 01/16 21:54