Object obj = parser.parse(new FileReader("path2JsonFIle")); JSONObject jsonObject = (JSONObject) obj;
try this iterator
JSONObject jsonObj = (JSONObject)jsonObject.get("this_guy"); for (Object key : jsonObj.keySet()) {
as soon as you get the appropriate value, just exit the loop. for example, you said that all you need is the first value on the internal map. so try something like
int count = 0; String valuINeed=""; for (Object key : jsonObj.keySet()) { //based on you key types String keyStr = (String)key; Object keyvalue = jsonObj.get(keyStr); valueINeed = (String)keyvalue; count++; /*check here for the appropriate value and do whatever you want*/ //Print key and value System.out.println("key: "+ keyStr + " value: " + keyvalue); if(count==1) break; } System.out.println(valueINeed);
source share