Android GET Request - No value for ImageUrl

258 views Asked by At

I am trying to perform a GET request to https://www.cryptocompare.com/api/data/coinlist/, I am grabbing the values "ImageUrl, "Name", and "CoinName". However, I am only receiving about ~230 values with an "ImageUrl". I should be receiving ~1470. This is the exception I receive. I am confused by this since I do a GET request using Postman and it has a value for every "ImageUrl".

org.json.JSONException: No value for ImageUrl

Here is the code for my GET request

@Override
public void GETCoins() {
    String url = "https://www.cryptocompare.com/api/data/coinlist/";
    Log.d("Debug ", "URL:  " + url);

    //Run async task to pull weather data. weatherTask.get... forces main thread to wait for this to finish
    HTTPAsyncTask coinTask = new HTTPAsyncTask(this);
    coinTask.execute(url, "GET");
    try {
        JSONObject jsonObject = new JSONObject(coinTask.get());

        JSONObject obj = new JSONObject(jsonObject.getString("Data"));

        Iterator<?> keys = obj.keys();
        int i = 0;
        while(keys.hasNext() ) {

            String key = (String) keys.next();

            if(obj.get(key) instanceof JSONObject) {
                JSONObject val = new JSONObject(obj.get(key).toString());

                String imageUrl = baseImageUrl + val.getString("ImageUrl");
                String name = val.getString("Name");
                String currency = val.getString("CoinName");

                CryptoData data = new CryptoData(i, currency, 0,0, imageUrl, name);

                allCurrencyList.add(data);
                i++;
            }
        }

        //updateData(jsonObject);

    } catch (InterruptedException | JSONException | ExecutionException e) {
        e.printStackTrace();
    } finally {
        Log.d("Debug ", "Coin API is null");
    }
}
0

There are 0 answers