Bonjour,

J'ai un petit souci pour parser du JSON.

Pour m'aider, j'ai repris cet exemple qui marche très bien : http://www.androidhive.info/2012/01/...sing-tutorial/

Le fichier JSON est de type :
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
{
****"contacts":*[
********{
****************"id":*"c200",
****************"name":*"Ravi*Tamada",
****************"email":*"ravi@gmail.com",
****************"address":*"xx-xx-xxxx,x*-*street,*x*-*country",
****************"gender"*:*"male",
****************"phone":*{
********************"mobile":*"*+91*0000000000",
********************"home":*"00*000000",
********************"office":*"00*000000"
****************}
********},
********{
****************"id":*"c201",
****************"name":*"Johnny*Depp",
****************"email":*"johnny_depp@gmail.com",
****************"address":*"xx-xx-xxxx,x*-*street,*x*-*country",
****************"gender"*:*"male",
****************"phone":*{
********************"mobile":*"*+91*0000000000",
********************"home":*"00*000000",
********************"office":*"00*000000"
****************}
********},
********.
********.
********.
********.
**]
}
Mais le problème et que je dois parser un fichier du type :
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
{
"expirationDate":"2012-12-16*3:45",
"lines":
{
"line":[
{
**********"color"*********:*"(255,0,0)",
**********"id"************:*"11821949021891694",
**********"name"**********:*"Basso*Cambo*/*Balma-Gramont",
**********"shortName"*****:*"A",**********
**********"network"*******:*"Tisséo",
**********"transportMode"*:
*****************{*********
******************"id"*****:"13792273858822586",
******************"article":*"le",
******************"name"***:*"métro"
****************}*************************
********}
********,{
**********"color"*********:*"(255,94,22)",
**********"id"************:*"11821949021891902",
**********"name"**********:*"Navette*aéroport",
**********"shortName"*****:*"AERO",**********
**********"network"*******:*"Tisséo",
**********"transportMode"*:
*****************{*********
******************"id"*****:"13792273858822585",
******************"article":*"le",
******************"name"***:*"bus"
****************}*************************
********}
********,
.
.
.
J'ai donc essayé de modifier le code du tutoriel cité plus haut de cette manière(mais rien ne s'affiche, par contre l'application ne plante pas) :
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
private static String url = "http://pt.data.tisseo.fr/linesList?format=json";
 
    // JSON Node names
    private static final String TAG_expirationDate = "expirationDate";
    private static final String TAG_line = "line";
    private static final String TAG_color = "color";
    private static final String TAG_id = "id";
    private static final String TAG_name = "name";
    private static final String TAG_shortName = "shortName";
    private static final String TAG_network = "network";
    private static final String TAG_transportMode = "transportMode";
    private static final String TAG_id_transportMode = "id_transportMode";
    private static final String TAG_article = "article";
    private static final String TAG_name_transportMode = "name_transportMode";
 
    // contacts JSONArray
    JSONArray line = null;
    String expirationDate = null;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        // Hashmap for ListView
        ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
 
        // Creating JSON Parser instance
        JSONParser jParser = new JSONParser();
 
        // getting JSON string from URL
        JSONObject json = jParser.getJSONFromUrl(url);
 
        try {
            expirationDate = json.getString(TAG_expirationDate);
            // Getting Array of Contacts
            line = json.getJSONArray(TAG_line);
 
            // looping through All Contacts
            for(int i = 0; i < line.length(); i++){
                JSONObject l = line.getJSONObject(i);
 
                // Storing each json item in variable
                String color = l.getString(TAG_color);
                String id = l.getString(TAG_id);
                String name = l.getString(TAG_name);
                String shortName = l.getString(TAG_shortName);
                String network = l.getString(TAG_network);
 
                // Phone number is agin JSON Object
                JSONObject transportMode = l.getJSONObject(TAG_transportMode);
                String id_transportMode = transportMode.getString(TAG_id_transportMode);
                String article = transportMode.getString(TAG_article);
                String name_transportMode = transportMode.getString(TAG_name_transportMode);
 
                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();
 
                // adding each child node to HashMap key => value
                map.put(TAG_name, name);
                map.put(TAG_shortName, shortName);
                map.put(TAG_network, network);
                map.put(TAG_name_transportMode, name_transportMode);
 
                // adding HashList to ArrayList
                contactList.add(map);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
Je pense que le probleme vient du début du fichier mais je ne trouve pas de solution...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
{
"expirationDate":"2012-12-16*3:45",
"lines":
Quelqu'un aurait une idée du problème ?

Merci d'avance pour votre aide.