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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| public void downloadListOnline(){
new Thread( new Runnable( ){
public void run() {
InputStream is=null;
JSONObject json_data;
String result = "";
HttpEntity entity = null;
try{
result = "";
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("action","actionafaire")); //key + string data
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.vers.tonfichier.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8));
HttpResponse response = httpclient.execute(httppost);
entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF8"),8 * 1024);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
if (result.trim().equals("null")){
if (D) Log.d(TAG, "liste vide !");
}else{
JSONArray jArray = new JSONArray(result);
String[][] recup=new String[jArray.length()][6];
String[] same = null;
for(int i=0;i<jArray.length();i++){
json_data = jArray.getJSONObject(i);
recup[i][0]= json_data.getString("listname");
recup[i][1]= json_data.getString("article");
} // fin for
} // si result pas null
}catch(JSONException e){
e.printStackTrace();
}
} // end run
}).start();
} |
Partager