Stack Exchange
How to store URL from JSON object request when JSON object URL field contains multiple URL in android studio?
Main Activity File code-
...
    import android.content.Intent
    import android.content.Intent.createChooser
    import android.graphics.drawable.Drawable
    import androidx.appcompat.app.AppCompatActivity
    import android.os.Bundle
    import android.util.Log
    import android.view.View
    import android.widget.Toast
    import com.android.volley.Request
    import com.android.volley.toolbox.JsonObjectRequest
    import com.bumptech.glide.Glide
    import com.bumptech.glide.load.DataSource
    import com.bumptech.glide.load.engine.GlideException
    import com.bumptech.glide.request.RequestListener
    import com.example.memesexplorer.databinding.ActivityMainBinding
    import com.bumptech.glide.request.target.Target
    
    class MainActivity : AppCompatActivity() {
        private var currentUrl: String? = null
        private lateinit var binding: ActivityMainBinding
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            binding = ActivityMainBinding.inflate(layoutInflater)
            val view = binding.root
            setContentView(view)
    
            loadImage()
        }
    
        private fun loadImage() {
            binding.next.isEnabled=false
            binding.share.isEnabled=false
            binding.buffer.visibility=View.VISIBLE
    
            val url="https://api.unsplash.com/photos/random?client_id=Q-fqoRMI-t8jb8se08Ow5hebv7KsDdWUBadjBwfqsxg"
            val jsonObjectRequest = JsonObjectRequest(
                Request.Method.GET, url,null,
                { response ->
                    Log.d("Response Check","Entered the response")
                    binding.buffer.visibility=View.GONE
                    currentUrl=response.getString("url")
                    Glide.with(this).load(currentUrl).listener(object : RequestListener<Drawable> {
                        override fun onResourceReady(
                            resource: Drawable?,
                            model: Any?,
                            target: Target<Drawable>?,
                            dataSource: DataSource?,
                            isFirstResource: Boolean
                        ): Boolean {
                            binding.buffer.visibility = View.GONE
                            binding.next.isEnabled = true
                            binding.share.isEnabled = true
                            return false
                        }
    
                        override fun onLoadFailed(
                            e: GlideException?,
                            model: Any?,
                            target: Target<Drawable>?,
                            isFirstResource: Boolean
                        ): Boolean {
                            binding.buffer.visibility = View.GONE
                            binding.next.isEnabled = true
                            binding.share.isEnabled = true
                            Toast.makeText(this@MainActivity,"Image can't be loaded",Toast.LENGTH_LONG).show()
                            return false
                        }
                    }).into(binding.img)
                }
            ) {
                binding.buffer.visibility = View.GONE
                binding.next.isEnabled = true
                binding.share.isEnabled = true
                Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show()
            }
            Network.getInstance(this).addToRequestQueue(jsonObjectRequest)
        }
    
    }

...
I want changes in assigning value to currentUrl variable in loadImage() function so that it can store URL of the image that can be loaded in img ImageView.
The API link used is- https://api.unsplash.com/photos/random?client_id=Q-fqoRMI-t8jb8se08Ow5hebv7KsDdWUBadjBwfqsxg
JSON object for the API used is-
...
id: "JS2IVAyMsM0",
created_at: "2021-03-24T05:19:52-04:00",
updated_at: "2021-04-06T06:41:49-04:00",
promoted_at: "2021-03-24T10:21:01-04:00",
width: 3264,
height: 4896,
color: "#8cd9d9",
blur_hash: "L=F%rTt7oLoeyskCWCbHNxj[oLay",
description: null,
alt_description: "brown and white concrete buildings under blue sky during daytime",
urls: {
raw: "https://images.unsplash.com/photo-1616577441006-8a6b3fc50a7d?ixid=MnwyMjExMjV8MHwxfHJhbmRvbXx8fHx8fHx8fDE2MTc3NzU5MTE&ixlib=rb-1.2.1",
full: "https://images.unsplash.com/photo-1616577441006-8a6b3fc50a7d?crop=entropy&cs=srgb&fm=jpg&ixid=MnwyMjExMjV8MHwxfHJhbmRvbXx8fHx8fHx8fDE2MTc3NzU5MTE&ixlib=rb-1.2.1&q=85",
regular: "https://images.unsplash.com/photo-1616577441006-8a6b3fc50a7d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwyMjExMjV8MHwxfHJhbmRvbXx8fHx8fHx8fDE2MTc3NzU5MTE&ixlib=rb-1.2.1&q=80&w=1080",
small: "https://images.unsplash.com/photo-1616577441006-8a6b3fc50a7d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwyMjExMjV8MHwxfHJhbmRvbXx8fHx8fHx8fDE2MTc3NzU5MTE&ixlib=rb-1.2.1&q=80&w=400",
thumb: "https://images.unsplash.com/photo-1616577441006-8a6b3fc50a7d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwyMjExMjV8MHwxfHJhbmRvbXx8fHx8fHx8fDE2MTc3NzU5MTE&ixlib=rb-1.2.1&q=80&w=200"
},
links: {
self: "https://api.unsplash.com/photos/JS2IVAyMsM0",
html: "https://unsplash.com/photos/JS2IVAyMsM0",
download: "https://unsplash.com/photos/JS2IVAyMsM0/download",
download_location: "https://api.unsplash.com/photos/JS2IVAyMsM0/download?ixid=MnwyMjExMjV8MHwxfHJhbmRvbXx8fHx8fHx8fDE2MTc3NzU5MTE"
},
categories: [ ],
likes: 128,
liked_by_user: false,
current_user_collections: [ ],
sponsorship: null,
user: {
id: "VeIm9BP-du0",
updated_at: "2021-04-07T02:09:48-04:00",
username: "cristina_gottardi",
name: "Cristina Gottardi",
first_name: "Cristina",
last_name: "Gottardi",
twitter_username: null,
portfolio_url: "https://www.instagram.com/cristinagottardi/",
bio: "Hi! I’m an enthusiastic 28 year old Web Designer living and working in Milan. I'm from Trentino - in northern Italy - and I'm in love with the silence of landscapes and views hidden by my beloved mountains. ",
location: "Trento, North Italy",
links: {
self: "https://api.unsplash.com/users/cristina_gottardi",
html: "https://unsplash.com/@cristina_gottardi",
photos: "https://api.unsplash.com/users/cristina_gottardi/photos",
likes: "https://api.unsplash.com/users/cristina_gottardi/likes",
portfolio: "https://api.unsplash.com/users/cristina_gottardi/portfolio",
following: "https://api.unsplash.com/users/cristina_gottardi/following",
followers: "https://api.unsplash.com/users/cristina_gottardi/followers"
},
profile_image: {
small: "https://images.unsplash.com/profile-1509140709644-5b9d6cd408f9?ixlib=rb-1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=32&w=32",
medium: "https://images.unsplash.com/profile-1509140709644-5b9d6cd408f9?ixlib=rb-1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=64&w=64",
large: "https://images.unsplash.com/profile-1509140709644-5b9d6cd408f9?ixlib=rb-1.2.1&q=80&fm=jpg&crop=faces&cs=tinysrgb&fit=crop&h=128&w=128"
},
instagram_username: "cristina.gottardi",
total_collections: 0,
total_likes: 291,
total_photos: 380,
accepted_tos: true,
for_hire: false
},
exif: {
make: "FUJIFILM",
model: "X-T10",
exposure_time: "1/420",
aperture: "9.0",
focal_length: "27.0",
iso: 400
},
location: {
title: "Lucca, LU, Italia",
name: "Lucca, LU, Italia",
city: "Lucca",
country: "Italia",
position: {
latitude: 43.84292,
longitude: 10.502698
}
},
views: 560463,
downloads: 1769
}

...
JSON object urls block consist of many URLs but I want to store value of 1 URL among them in the currentURL variable.
Please someone just go through the code and help me by suggesting changes in my code so I can do it.

You need to access the urls object to get the desired image sizes.
For this example, I used the full one.
currentUrl = response.getJSONObject("urls").getString("full")

