android - How to convert Shift-JIS encoded string to UTF-8? -
i getting html source aozora bunko. html file shift-jis encoded. trying book title , author. want record title , author sqlite(utf-8) database.
string[] splittedresult = result.split("\"title\">"); splittedresult = splittedresult[1].split("</h1>"); string title = splittedresult[0]; byte[] b = null; try { b = title.getbytes("shift_jis"); } catch (unsupportedencodingexception e1) { // todo auto-generated catch block e1.printstacktrace(); } string value=null; try { value = new string(b, "utf-8"); } catch (unsupportedencodingexception e1) { // todo auto-generated catch block e1.printstacktrace(); } ... mydatabase.addbookinformation(value, author);
result this: latin letters showing normally. japanese letters shown blocks question mark inside (please not pay attention null values)
how solve problem?
as @codo pointed out, solution problem before. changed this
s = entityutils.tostring(response.getentity(), "utf-8");
to this
s = entityutils.tostring(response.getentity(), "shift_jis");
and there no need encoding.
string[] splittedresult = result.split("\"title\">"); splittedresult = splittedresult[1].split("</h1>"); string title = splittedresult[0]; /** have taken part of code byte[] b = null; try { b = title.getbytes("shift_jis"); } catch (unsupportedencodingexception e1) { // todo auto-generated catch block e1.printstacktrace(); } string value=null; try { value = new string(b, "utf-8"); } catch (unsupportedencodingexception e1) { // todo auto-generated catch block e1.printstacktrace(); } **/
Comments
Post a Comment