String encoding - Shift_JIS / UTF-8

后端 未结 1 586
走了就别回头了
走了就别回头了 2021-01-15 23:28

I get a string from a 3rd party library, which is not well encoded. Unfortunately I\'m not allowed to change the library or use another one...

So the actual problem

相关标签:
1条回答
  • 2021-01-15 23:42

    Well, very strange:

    As

    byte[] b = resultString.getBytes("Shift_JIS");
    String value = new String(b, "UTF-8");
    

    didn't work for me I tried the following:

    String value = new String(resultString.getBytes("SHIFT-JIS"), "UTF-8")
    

    Works like a charm. Maybe it was because of the underscore and lower case character in "Shift_JIS".

    0 讨论(0)
提交回复
热议问题