java 将字符串中含有unicode 转成中文

xiaoxiao2021-02-28  115

private static String ascii2native ( String asciicode )     {         String[] asciis = asciicode.split ("\\\\u");         String nativeValue = asciis[0];         try         {             for ( int i = 1; i < asciis.length; i++ )             {                 String code = asciis[i];                 nativeValue += (char) Integer.parseInt (code.substring (0, 4), 16);                 if (code.length () > 4)                 {                     nativeValue += code.substring (4, code.length ());                 }             }         }         catch (NumberFormatException e)         {             return asciicode;         }         return nativeValue;     }       public static void main ( String[] args )     {         String str = "\"JWHQK_JWQC\":\"\u6c5f\u5b89\u793e\u533a\u5c45\u6c11\u59d4\u5458\u4f1a\"";         String result = ascii2native (str);         System.out.println(result);     }
转载请注明原文地址: https://www.6miu.com/read-19873.html

最新回复(0)