2017  Kodetalk | Feedback | Privacy Policy | Terms | About

Iterate through JSONObject from root in json simple

Want to Iterate below JSon object in java


by usingIterator iter = jObj.keys();

And got the below exception,

throws: cannot find symbol symbol : method keys() location: class org.json.simple.JSONObject


Hope it will be solve your problem,

JSONParser parser = new JSONParser();

Object obj = parser.parse(new FileReader("simple.json")); //Assuming your JSON object is saved in a file "simple.json"

JSONObject jsonObject = (JSONObject) obj;

for(Iterator iterator = jsonObject.keySet().iterator(); iterator.hasNext();) {
    String key = (String) iterator.next();

Answer is