Convert UTF-16 unicode characters to UTF-8 in java

前端 未结 2 1410
眼角桃花
眼角桃花 2020-12-28 17:12

When I got JSON then there are \\u003c and \\u003e instead of < and >. I want to convert them back to utf-8 in java. any help will be highly appreciated. Thanks.

2条回答
  •  被撕碎了的回忆
    2020-12-28 17:59

    try {
        // Convert from Unicode to UTF-8
        String string = "\u003c";
        byte[] utf8 = string.getBytes("UTF-8");
    
        // Convert from UTF-8 to Unicode
        string = new String(utf8, "UTF-8");
    } catch (UnsupportedEncodingException e) {
    }
    

    refer http://www.exampledepot.com/egs/java.lang/unicodetoutf8.html

提交回复
热议问题