HttpClient 解析 jsonArray数据

来源:互联网 发布:provider sql network 编辑:程序博客网 时间:2024/06/06 10:39

代码如下:

    public static JSONArray getJsonArray(String url) throws IOException, JSONException {        HttpClient httpClient = new DefaultHttpClient();        HttpGet httpRequest = new HttpGet(url);        HttpResponse httpResponse = httpClient.execute(httpRequest);        if(httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK){            String strResult = EntityUtils.toString(httpResponse.getEntity());            JSONArray jsonArray = new JSONArray(strResult);            return jsonArray;        }        return null;    }

对jsonArray的解析如下:

JSONArray jsonArray = HttpUtil.getJsonArray(url);        for(int i=0, len=jsonArray.length(); i<len; i++){            JSONObject jsonObject = jsonArray.getJSONObject(i);            String date = jsonObject.get("FromTime").toString();            Long dateLong = StrUtils.getTime(date);            System.out.println("title:" + dateLong);        }


原创粉丝点击