Reputation: 452
What I want to achieve is to check if all the values of a JSON object is of type String. I have read about JSONObject's getString
method and thought about making a while-loop that iterates through a JSON object, but I think this will be an inefficient solution to the problem.
Is there a library that can achieve value-type checking for all values of a JSON object? (ex. all JSON values are String, Integer, boolean, etc.)
Any advice/tip is greatly appreciated.
Upvotes: 0
Views: 319
Reputation: 145
Iterator<String> keys = jsonObject.keys();
while(keys.hasNext()) {
String key = keys.next();
if (jsonObject.get(key) instanceof String) {
// do something with jsonObject here
}
}
Upvotes: 1