URLConnection connection = null;
try {
connection = new URL("地址...").openConnection();
connection.connect();
InputStream fin = connection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(fin));
StringBuffer buffer = new StringBuffer();
String temp = null;
while ((temp = br.readLine()) != null) {
buffer.append(temp);
}
JSONArray ct = new JSONArray(buffer.toString());
BufferedReader br = new BufferedReader(new InputStreamReader(fin));
StringBuffer buffer = new StringBuffer();
String temp = null;
while ((temp = br.readLine()) != null) {
buffer.append(temp);
}
JSONArray ct = new JSONArray(buffer.toString());
for (int i = 0; i < ct.length(); i++) {
JSONObject obj = ct.getJSONObject(i);
obj.get("key");//key...
}
JSONObject obj = ct.getJSONObject(i);
obj.get("key");//key...
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
本文介绍了一种使用Java进行网络请求的方法,并展示了如何通过URLConnection从指定URL获取数据,然后利用JSON解析技术处理响应结果。



被折叠的 条评论
为什么被折叠?



