彻底解决Android中文乱码

以下是我研究的成果,希望对您有帮助:

  Java代码

  sb = new StringBuffer();

  HttpEntity entity = response.getEntity();

  InputStream is = entity.getContent();

  BufferedReader br = new BufferedReader(

  new InputStreamReader(is,"GB2312"));

  String data = "";

  while ((data = br.readLine()) != null) {

  sb.append(data);

  }

  String result = sb.toString();

  sb = new StringBuffer();

  HttpEntity entity = response.getEntity();

  InputStream is = entity.getContent();

  BufferedReader br = new BufferedReader(

  new InputStreamReader(is,"GB2312"));

  String data = "";

  while ((data = br.readLine()) != null) {

  sb.append(data);

  }

  String result = sb.toString();

  Java代码

  //下面的是多余的代码,平台会按照默认编码读数据,谢谢melode11和eleda指点 result = new String(result.getBytes(),"UTF-8");

  //下面的是多余的代码,平台会按照默认编码读数据,谢谢melode11和eleda指点 result = new String(result.getBytes(),"UTF-8");

  我解释一下,

  Java代码

  BufferedReader br = new BufferedReader(

  new InputStreamReader(is,"GB2312"));

  BufferedReader br = new BufferedReader(

  new InputStreamReader(is,"GB2312"));

  是读取要改编码的源,源的格式是GB2312的,安源格式读进来,然后再对源码转换成想要的编码就行

http://www.inandroid.cn/bbs/thread-3320-1-1.html

你可能感兴趣的:(java,android,String,null,平台)