1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(strURL);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(IOException e){
Toast.makeText(HelloGoogleMapActivity.this,"Problème de connection au serveur 1",Toast.LENGTH_SHORT).show();
Log.e("log_tag", "Error in http connection " + e.toString());
}
// Convertion de la requête en string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Toast.makeText(HelloGoogleMapActivity.this,"Problème de connection au serveur 2",Toast.LENGTH_SHORT).show();
Log.e("log_tag", "Error converting result " + e.toString());
}
// Parse les données JSON
try{
JSONArray jArray = new JSONArray(result);
tabAlt=new int[jArray.length()];
tabLong=new int[jArray.length()];
tabNomAgence=new String[jArray.length()];
for(int i=0;i<jArray.length();i++)
{ Log.i("N","Nouvelle ligne");
String var=jArray.getJSONObject(i).toString();
}
}catch(JSONException e){
Toast.makeText(HelloGoogleMapActivity.this,"Problème de connection au serveur 3",Toast.LENGTH_SHORT).show();
Log.e("log_tag", "Error parsing data " + e.toString());
} |
Partager