package com.example.testes import android.util.Log import org.json.JSONArray import org.json.JSONException import org.json.JSONObject data class BooruImage ( var id: String, var rating: String, var tags: String, var file_url: String, var preview_url: String, ) { fun clone(): BooruImage { return BooruImage(id, rating, tags, file_url, preview_url) } companion object { @Throws(JSONException::class) fun imageFromJson(json: JSONObject): BooruImage { val id = json.getInt("id").toString() val rating = json.getString("rating") val tags = json.getString("tags") val file_url = json.getString("file_url") val preview_url = json.getString("preview_url") return BooruImage(id, rating, tags, file_url, preview_url) } @Throws(JSONException::class) fun listFromJsonArray(array: JSONArray): MutableList { val imageList: MutableList = mutableListOf() for (i in 0 until array.length()) { imageList.add(imageFromJson(array.getJSONObject(i))) } return imageList } } }