[問題] 請問big5編碼

看板AndroidDev作者 (270度的鳥顧之相)時間14年前 (2012/01/16 00:32), 編輯推噓0(006)
留言6則, 1人參與, 最新討論串1/2 (看更多)
想請教一下大家在處理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)

01/16 21:48, , 1F
為什麼回應字串要轉編碼兩次???
01/16 21:48, 1F

01/16 21:49, , 2F
既然已經知道source是big5,要轉成UTF-8,直接
01/16 21:49, 2F

01/16 21:51, , 3F
strRet = new String(
01/16 21:51, 3F

01/16 21:52, , 4F
EntityUtils.toString(response.getEntity())
01/16 21:52, 4F

01/16 21:52, , 5F
.getBytes("ISO-8859-1"), "UTF-8")
01/16 21:52, 5F

01/16 21:54, , 6F
至於>、<、&這種特殊符號,除了tag以外,都要自己轉換格式
01/16 21:54, 6F
文章代碼(AID): #1F4l-d8x (AndroidDev)
討論串 (同標題文章)
文章代碼(AID): #1F4l-d8x (AndroidDev)