Bonjour,
J'ai deux List JSON de la forme myArrayList2 = ["a1","a2","a3"] et myArrayList4 = ["b1","b2","b3].
Je veux combiner pour en faire un seul fichier JSON de la forme [{ "nom" : "a1", "prenom" : "b1"}, {"nom" : "a2", "prenom" : "b2"}, {"nom" : "a3", "prenom" : "b3" }].
J'ai écrit :
Mais le résultat obtenu est : [{ "nom" : "a3", "prenom" : "b3"}, {"nom" : "a3", "prenom" : "b3"}, {"nom" : "a3", "prenom" : "b3" }] .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 public Object dataFinaux() { JSONArray jsonArray = new JSONArray(); JSONObject valuesObject = new JSONObject(); for (int k = 0; k < myArrayList2.size(); k++) { valuesObject.put("nom", myArrayList4.get(k)); valuesObject.put("prenom", myArrayList2.get(k)); jsonArray.add(valuesObject); } return jsonArray;
Pouvez-vous m'aidez svp ?
Merci d'avance
Partager