You should declare a

```java
   final int len = json.length();
```

as you use it several times (and it will be reevaluated at every loop occurrence below). I haven't looked at the `JSONArray` methods, but maybe there is a better iterator than that.