Dynamic Json Object Keyset Finding
import java.util.Iterator;
import java.util.Set;
import org.json.simple.JSONObject;
public class Json {
public static void main(String[] args) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("a", "aaa");
jsonObject.put("b", "bbb");
Set keys = jsonObject.keySet();
Iterator a = keys.iterator();
while(a.hasNext()) {
String key = (String)a.next();
// loop to get the dynamic key
String value = (String)jsonObject.get(key);
System.out.print("key : "+key);
System.out.println(" value :"+value);
}
}
}
thank you.. so helpfull :D
ReplyDeleteYou are welcome (y)
Deletegood one
Delete@Devan,
ReplyDeleteCan you please help me iterate thru the "value" if it is an Object itself ... so basically get the "keys" for nested JSON.
Best,
Jigs