Problème parsing JSON avec Jackson
Bonjour,
J'ai suivi ce tutoriel pour faire le parsing JSON => http://nbenbourahla.developpez.com/t...ckson-android/
Mais j'ai un problème, je ne comprend pas pourquoi mais si je rajoute certains champs à mon fichier json, cela fait planter mon application.
Je m'explique, si mon fichier JSON est de cette forme :
Code:
{"Members":[{"nom":"Toto albert","role":"Pr\u00e9sident","tel":"0600000000","mail":"toto@toto.fr","description":"salut"}]}
Tout ce passe bien, mais si je rajoute un champ :
Code:
{"Members":[{"nom":"Toto albert","role":"Pr\u00e9sident","tel":"0600000000","mail":"toto@toto.fr","description":"salut","img_path":"toto.png"}]}
Mon application plante, alors que je n'ai pas changer le code entre temps.
Voici le code d'erreur :
Code:
03-04 09:20:28.723: E/AndroidRuntime(330): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bde.ismin/com.bde.ismin.StaffActivity}: java.lang.NullPointerException
L'erreur apparaît lors de l'appel à la fonction "findall"
Code:
1 2 3
| public ArrayList<Member> findAll() {
return memberList;
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| public void init(String url_str) {
downloadJsonFile(url_str);
try {
jp = jsonFactory.createJsonParser(jsonFile);
events = objectMapper.readValue(jp, Members.class);
memberList = events.get("Members");
} catch (JsonParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} |
Voici enfin le parsing dans mon application
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| ArrayList<HashMap<String, String>> StaffList = new ArrayList<HashMap<String, String>>();
staffController = new StaffController();
staffController.init(BDEISMINActivity.DL_URL_STAFF);
for (Member u : staffController.findAll()) {
HashMap<String, String> map = new HashMap<String, String>();
//map.put(BDEISMINActivity.KEY_ID, "1");//u.getName());
map.put(BDEISMINActivity.KEY_TITLE,u.getNom());// u.getTime());
map.put(BDEISMINActivity.KEY_MORE, u.getRole());//u.getPlace());
map.put(BDEISMINActivity.KEY_RIGHTEND, u.getTel());//u.getName());
map.put(BDEISMINActivity.KEY_THUMB_URL, BDEISMINActivity.URL_PHOTO_PATH_STAFF + "toto.png");
StaffList.add(map);
}
list_staff=(ListView)findViewById(R.id.list_staff);
adapter= new LazyAdapter(this, StaffList);
list_staff.setAdapter(adapter); |
Voici ma classe "Member"
Code:
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
| public class Member {
private String nom;
private String role;
private String tel;
private String mail;
private String description;
private String img_path;
private String room;
public Member() {
super();
this.nom = "";
this.role = "";
this.tel = "";
this.mail = "";
this.description = "";
this.img_path = "";
this.room = "";
}
public Member(String Nom, String Role, String Tel, String Mail,
String Description, String Img_Path, String Room) {
super();
this.nom = Nom;
this.role = Role;
this.tel = Tel;
this.mail = Mail;
this.description = Description;
this.img_path = Img_Path;
this.room = Room;
}
[...] |
Le but est que j'ai plusieurs membres avec chacun ça photo, du coup j'aimerai pouvoir la récupérer via JSON..
Voilà merci de votre aide, j'espère ne rien avoir oublié...
Bye
Ludo