I have a collection of keys in my jsonObject and i need to iterate through this collection. Code copied from https://stackoverflow.com/a/17399110/1264217 And my code is:
public static void parseJson(JSONObject jsonObject, String dir) throws ParseException {
//Set<Object> set = jsonObject.keySet();
ArrayList<JSONObject> arrays=new ArrayList<JSONObject>();
Iterator<Object> iterator = jsonObject.keys();
while (iterator.hasNext()) {
Object obj = iterator.next();
try {
if (jsonObject.get((String) obj) instanceof JSONArray) {
System.out.println(obj.toString());
getArray(jsonObject.get((String) obj));
} else {
if (jsonObject.get((String) obj) instanceof JSONObject) {
dir=dir+(String)obj+"/";
parseJson((JSONObject) jsonObject.get((String) obj),dir);
dir=dir.replace((String)obj+"/","");
} else {
String path=dir+obj.toString();
System.out.println(obj.toString() + "\t"
+ jsonObject.get((String) obj));
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
After the execution of First line it shows me my collection of 4(which is correct) but "LastEntryreturned" points to last key and "next()" to null so after second line code it ends the loop and returns result without iterate over the collection.
This code was working good 2 days ago but i dont know what happened with it now. Please help me i have already spent too much time on it...