title: Kotlin: Iterate through a JSONArray
body: <p>I'm writing an Android app using Kotlin and Realm.
  I have a JSONArray, and I want to iterate through the JSONObjects in this array in order to load them in a Realm database class:</p>
  
  <p>Realm class:</p>
  
  <pre><code>import io.realm.RealmObject
  import io.realm.annotations.PrimaryKey
  import io.realm.annotations.Required
  
  open class Person(
  
          @PrimaryKey open var id: Long = 0,
  
          @Required
          open var name: String = ""
  
  ) : RealmObject() {
  
  }
  </code></pre>
  
  <p>The JSONArray:</p>
  
  <pre><code>{
      "persons":[
          {
             "id":0,
             "name":"Biatrix"
          },
          {
             "id":1,
             "name":"Bill"
          },
          {
             "id":2,
             "name":"Oren"
          },
          {
             "id":3,
             "name":"Budd"
          }
      ]
  }
  </code></pre>
  
  <p>I've tried iterating like the following:</p>
  
  <pre><code>for (item : JSONObject in persons) {
  
  }
  </code></pre>
  
  <p>... but I get a <code>for-loop range must have an iterator() method</code> error.</p>