I need to get image URL from JSON file. How to set ImageView src to be URL from file?
In the end I need to create grid of images. First I want to make one ImageView with src from JSON file. I managed to read JSON file, I can print URL using TextView, but can't figure out how to make that string an URL.
JSON file structure.
{
"name": "dog0",
"link": "https://images.unsplash.com/photo-1503256207526-0d5d80fa2f47?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=633&q=80"
}
This is how I read file, adding url's to an array.
fun readFile() {
var json : String? = null
try {
val inputStream:InputStream = assets.open("dogs.json")
json = inputStream.bufferedReader().use{it.readText()}
var jsonarr = JSONArray(json)
for (i in 0..jsonarr.length()-1){
var jsonobj = jsonarr.getJSONObject(i)
arr.add(jsonobj.getString("link"))
}
var adpt = ArrayAdapter(this, android.R.layout.simple_list_item_1,arr)
}
catch(e: IOException) {
}
}
I know it's possible to use external libraries to do such a thing, but I want to solve this problem without external stuff.
How to make ImageView have src from URL?