bonjour voila comme dit dans le titre je reccupere mon json ici :
http://www.pebdev.eu/www/querymh.php?option=comunes
je le converti en string,
et enssuite je le parse pour le stocker dans un arraylist qui ira dans un listview,
seulement il ne me liste qu'une commune je ne comprend pas voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 package com.testing.pack; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.reflect.Array; import java.net.URI; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.R.string; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.util.Log; import android.widget.ArrayAdapter; import android.widget.ListView; public class testing extends Activity { String url = "http://www.pebdev.eu/www/querymh.php?option=comunes"; String result; ListView lvListe; /** Called when the activity is first created. /**@return * @return **/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView list = (ListView)findViewById(R.id.lvListe); ArrayList<String> results = new ArrayList<String>(); StringBuffer stringBuffer = new StringBuffer(""); BufferedReader bufferedReader = null; try { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(); URI uri = new URI(url); httpGet.setURI(uri); HttpResponse httpResponse = httpClient.execute(httpGet); InputStream inputStream = httpResponse.getEntity().getContent(); bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String ligneCodeHTML = bufferedReader.readLine(); while (ligneCodeHTML != null){ stringBuffer.append(ligneCodeHTML); stringBuffer.append("\n"); ligneCodeHTML = bufferedReader.readLine(); } }catch (Exception e){ Log.e("Log_tag", "Erreur reccupération"+e.getMessage()); }finally{ if (bufferedReader != null){ try{ bufferedReader.close(); result = stringBuffer.toString(); }catch(IOException e){ Log.e("Log_Tag", e.getMessage()); } } } try { JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++){ JSONObject json_data = jArray.getJSONObject(i); results.add((String) json_data.get("communeNom")); list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results)); } } catch(JSONException e){ Log.e("log", e.toString()); } } }
Partager