调用微信公众号平台时,返回的提示信息中的中文一般都是unicode数据,在java中,常用的转换方法,是将unicode变换为byte数组,然后强制类型转换为string输出;示例代码如下
public void converTest(){
byte[] bn={(byte)0xe7,(byte)0xad,(byte)0xbe,(byte)0xe5,(byte)0x90,(byte)0x8d,(byte)0xe9,(byte)0x94,(byte)0x99,(byte)0xe8,(byte)0xaf,(byte)0xaf};
String s;
try{
s=new String(bn,"utf-8"); // 源码制 utf-8
}
catch(Exception e)
{
s="error";
}
System.out.println("转换后的:"+s);
}