I use a JSON library called JSONObject
(I don\'t mind switching if I need to).
I know how to iterate over JSONArrays
, but when I parse JSO
First put this somewhere:
private Iterable iteratorToIterable(final Iterator iterator) {
return new Iterable() {
@Override
public Iterator iterator() {
return iterator;
}
};
}
Or if you have access to Java8, just this:
private Iterable iteratorToIterable(Iterator iterator) {
return () -> iterator;
}
Then simply iterate over the object's keys and values:
for (String key : iteratorToIterable(object.keys())) {
JSONObject entry = object.getJSONObject(key);
// ...