boorujelly/app/src/main/java/com/example/testes/BooruImage.kt

31 lines
906 B
Kotlin

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 tags: String,
var url: String,
) {
companion object {
@Throws(JSONException::class)
fun imageFromJson(json: JSONObject): BooruImage {
val id = json.getInt("id").toString()
val tags = json.getString("tags")
val url = json.getString("file_url")
return BooruImage(id, tags, url)
}
@Throws(JSONException::class)
fun listFromJsonArray(array: JSONArray): MutableList<BooruImage> {
val imageList: MutableList<BooruImage> = mutableListOf()
for (i in 0 until array.length()) {
imageList.add(imageFromJson(array.getJSONObject(i)))
}
return imageList
}
}
}