Decoding html returned as json response - android

前端 未结 4 1812
独厮守ぢ
独厮守ぢ 2021-01-07 02:04

I am getting following encoded html as a json response and has no idea how to decode it to normal html string, which is an achor tag by the way.

x3ca hrefx3d         


        
4条回答
  •  Happy的楠姐
    2021-01-07 02:54

    The term you search for are "UTF8 Code Units". These Code units are basically a backslash, followed by a "x" and a hex ascii code. I wrote a little converter method for you:

    public static String convertUTF8Units(String input) {
        String part = "", output = input;
        for(int i=0;i<=input.length()-4;i++) {
            part = input.substring(i, i+4);
            if(part.startsWith("\\x")) {
                byte[] rawByte = new byte[1];
                rawByte[0] = (byte) (Integer.parseInt(part.substring(2), 16) & 0x000000FF);
                String raw = new String(rawByte);
                output = output.replace(part, raw);
            }
        }
    
        return output;
    }
    

    I know, its a bit frowzy, but it works :)

提交回复
热议问题