【发布时间】:2017-06-09 03:14:59
【问题描述】:
我正在尝试将连接字符串转换为缓冲区输入流,然后再转换为字符串,以便我可以将其更改为 json 格式,但在调试程序后无法继续
in = new BufferedInputStream(conn.getInputStream());
并直接进入return语句。请帮忙。
我关注了这篇文章:https://www.tutorialspoint.com/android/android_json_parser.htm
public String makeServiceCall(String input_url)
{
String response=null;
InputStream in=null;
StringBuffer sb = new StringBuffer();
try {
URL url= new URL(input_url);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
in = new BufferedInputStream(conn.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(in,"UTF-8"));
String inputLine = "";
while ((inputLine = br.readLine()) != null) {
sb.append(inputLine);
}
response = sb.toString();
}
catch (MalformedURLException e) {
Log.e(TAG, "MalformedURLException: " + e.getMessage());
}
catch (ProtocolException e) {
Log.e(TAG, "ProtocolException: " + e.getMessage());
}
catch (IOException e) {
Log.e(TAG, "IOException: " + e.getMessage());
}
catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
return response;
}
【问题讨论】:
-
我打赌你会得到一个例外...我赌 NOMTException ...
-
如何解决?
-
通过学习调试
标签: android json inputstream httpconnection