in Android
public static InputStream is = null; public static JSONArray json_array = null; public static DefaultHeepClient httpClient; public static void main(String getSERVER, String getURL, String getDB, String getID){ SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme(HttpHost.DEFAULT_SCHEME_NAME, PlainSocketFactory.getSocketFactory(),80)); HttpParams httpParams; httpParams = new BasicHttpParams(); HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(httpParams, HTTP.UTF_8); httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schReg),httpParams); HttpResponse response = null; try { Uri.Builder uriBuilder = new Uri.Builder(); uriBuilder.path(getURL); uriBuilder.appendQueryParameter("SERVER",getSERVER); uriBuilder.appendQueryParameter("ID",getID); uriBuilder.appendQueryParameter("db_name", getDB); response = httpClient.execute(new HttpHost(getSERVER),new HttpGet(uriBuilder.build().toString())); } catch(Exception e){ Log.e("Error","接続エラー"); return; } if(response.getStatusLine().getStatusCode() != HttpStatus.SC_OK){ Log.e("Error",response.getStatusLine().getStatusCode()); return; } StringBuilder json = new StringBuilder(); try { HttpEntity entity = response.getEntity(); InputStream input = entity.getContent(); InputStreamReader reader = new InputStreamReader(input); BufferedReader bufReader = new BufferedReader(reader); String line; while((line = bufReader.readLine()) != null){ json.append(line); } } catch(IOException e){ Log.e("Error", "バッファ読み込み失敗"); return; } try { JSONObject json_data = new JSONObject(json.toString()); json_array = json_data.getJSONArray("response"); } catch(JSONException e){ Log.e("Error","JSONデータが不正"); return; } return; }