you can test if a key exists with rootObj.has("1")
or use rootObj.optJSONObject("1");
the former returns true if this object has a mapping for name. The latter returns the value mapped by name if it exists and is a JSONObject
, null otherwise.
Or you can interate through the keys inside rootObj, this way:
Iterator<String> keys = jSearchData.keys();
while (keys.hasNext()) {
String key = keys.next();
JSONObject jNotification0 = jSearchData.optJSONObject(key);
if (jNotification0 != null) {
String text = jNotification0.getString("text");
String uID = jNotification0.getString("uID");
String id = jNotification0.getString("id");
}
}