代码如下:
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);
}