您的位置:首页 > 理论基础 > 计算机网络

java http请求 返回结果是json ,转成对象使用

2013-11-29 11:51 316 查看

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());

for (int i = 0; i < ct.length(); i++) {

JSONObject obj = ct.getJSONObject(i);

obj.get("key");//key...

}

} catch (IOException e) {

e.printStackTrace();

} catch (JSONException e) {

e.printStackTrace();

}

分享到:


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: