我正在开发一个安卓应用程序,它使用AsyncTasks从应用程序API中获取JSON数据。当我启动我的应用程序时,一切都很顺利,应用程序从API中获得了正确的信息。
我实现了ActionBar拉式刷新库,这样人们就可以拖动我的列表视图来刷新他们的数据。现在我的应用程序在这一点上崩溃了。
我的BufferedReader.readline没有接收任何文本,而是返回这样的字符串。
���ĥS��Zis�8�+(m��L�ޔ�i}�l�V�8��$AI0��(YN�o�lI�,9cO�V͇� $��F���f~4r֧D4>�?4b�Տ��P#��|xK#h�����`�4@H,+Q�7��L�每次我的应用程序想要接收数据时,都会创建一个新的AsyncTask,所以我不知道为什么我的读者会返回这样的东西……
我希望你们能告诉我怎么解决这个问题!
编辑:我就是这样得到数据的。
BufferedReader阅读器= null;尝试{ reader =新BufferedReader(新InputStreamReader(url.openStream(),"UTF-8"));} catch (IOException e1) { e1.printStackTrace();} 字符串s=空;字符串数据= "";尝试{ while ((s = reader.readLine()) != null) { data += s;}IOException (IOException e) { // TODO自动生成的catch块e.printStackTrace();}
发布于 2015-07-13 09:22:59
我只是遇到了同样的问题。我发现返回的HTML可能被压缩成GZIP格式。使用类似的方法来检查编码,并使用适当的流来解码内容:
URL urlObj = new URL(url);
URLConnection conn = urlObj.openConnection();
String encoding = conn.getContentEncoding();
InputStream is = conn.getInputStream();
InputStreamReader isr = null;
if (encoding != null && encoding.equals("gzip")) {
isr = new InputStreamReader(new GZIPInputStream(is));
} else {
isr = new InputStreamReader(is);
}
reader = new BufferedReader(isr);以此类推。
发布于 2014-03-08 23:54:37
你有没有测试过其他像BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));这样的诱捕
您可以检查此网页enconding.doc上的所有可获取内容。
https://stackoverflow.com/questions/22275438
复制相似问题