public String getWebContent(String url) { // 创建一个http请求对象 HttpGet request = new HttpGet(url); // 创建HttpParams以用来设置HTTP参数 HttpParams params = new BasicHttpParams(); // 设置连接超时或响应超时 // HttpConnectionParams.setConnectionTimeout(params, 3000); // HttpConnectionParams.setSoTimeout(params, 5000); // 创建一个网络访问处理对象 HttpClient httpClient = new DefaultHttpClient(params); try { // 执行请求参数项 HttpResponse response = httpClient.execute(request); // 判断是否请求成功 if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // 获得响应信息 String content = EntityUtils.toString(response.getEntity()); return content; } else { // 网连接失败,使用Toast显示提示信息 Toast.makeText( context, context.getResources().... public String getWebContent(String url) { // 创建一个http请求对象 HttpGet request = new HttpGet(url); // 创建HttpParams以用来设置HTTP参数 HttpParams params = new BasicHttpParams(); // 设置连接超时或响应超时 // HttpConnectionParams.setConnectionTimeout(params, 3000); // HttpConnectionParams.setSoTimeout(params, 5000); // 创建一个网络访问处理对象 HttpClient httpClient = new DefaultHttpClient(params); try { // 执行请求参数项 HttpResponse response = httpClient.execute(request); // 判断是否请求成功 if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // 获得响应信息 String content = EntityUtils.toString(response.getEntity()); return content; } else { // 网连接失败,使用Toast显示提示信息 Toast.makeText( context, context.getResources().getString( R.string.connected_fails), 3000).show(); } } catch (Exception e) { // e.printStackTrace(); } finally { // 释放网络连接资源 httpClient.getConnectionManager().shutdown(); } return null; }content:即为json数据。