java后台请求http后,返回json格式的数据,但是中文部分显示乱码。
String uri = gps_url + "&uid=" +uid+ "&uKey=" +uKey+"";
URL url = new URL(uri);
String str ="";
BufferedReader bf = new BufferedReader(new InputStreamReader(url.openStream()));
while(null != (str = bf.readLine())){
System.out.println(str);
}
str控制台打印出来
{"version":1,"success":true,"data":[{"id":6472767,"name":"闄旳X698V澶т紬",。。。
求大神解决一下
BufferedReader中设置GB2312
我设置成了utf-8
谢大神!!已解决!!!
@kmanng: 怎么设置的哦
@黄哥是无敌是: BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream(),"utf-8"));
response设置一下编码格式
我设置了,但是依旧不对啊!!
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
response.setContentType("utf-8");
response.setCharacterEncoding("utf-8");
}
页面是什么编码?
java后台是可以设置的
InputStream inputStream = new InputStreamReader(url.openStream());
Reader reader = new InputStreamReader(inputStream, "UTF-8");
BufferedReader bf = new BufferedReader(reader);