I'm trying to parse list of array from json object like below code,
File file = new File(HomePage.jsonFilePath);
if (file.exists()) {
JSONParser parser = new JSONParser();
try {
Object obj = parser.parse(new FileReader(file));
JSONObject jsonObject = (JSONObject) obj;
System.out.println("Customer json for config customer " + jsonObject.toString());
configuredBranch = (String) jsonObject.get("branch");
configuredSystem = (String) jsonObject.get("system");
expinContainerPath = (String) jsonObject.get("path");
if (isEditable) {
try {
JSONArray customerArray = (JSONArray) jsonObject.get("customer_list");
if (customerArray != null && customerArray.size() > 0) {
Iterator<String> iterator = customerArray.iterator();
while (iterator.hasNext()) {
System.out.println("customer gson" + iterator.next());
customerList.add(iterator.next());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
And the console shows the below json when executing this line System.out.println("Customer json for config customer "+jsonObject.toString());
{"path":"C:\\Users\\Documents","system":"Exp","customer_list":["test","test1"],"branch":"LRD"}
But while iterating and printing like below System.out.println("customer gson"+iterator.next()); Its always prints test i.e first item in customer_list. I want to display all items in "customer_list". Could you please suggest me any idea to do this? thanks in advance.