首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

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

2012-11-23 
java http请求 返回结果是json ,转成对象使用?URLConnection connection null??????? try {???????????

java http请求 返回结果是json ,转成对象使用
?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();
??????? }

热点排行