Android中文乱码彻底解决

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

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

我解释一下,

BufferedReader br = new BufferedReader(
							new InputStreamReader(is,"GB2312"));

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

你可能感兴趣的:(android)