0

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");
    }
}
tom
  • 21,844
  • 6
  • 43
  • 36
tlarsin
  • 41
  • 2
  • You need check the Json string sent by checking the last data you received. – Prodigy Aug 28 '17 at 23:05
  • You cannot use .execute() and .get() on the same AsyncTask instance. If you only do a .get then the task does not know an url as you can see. – greenapps Aug 29 '17 at 09:54
  • Okay. I for some reason get 1400+ values for "Url", but only ~200 for "ImageUrl". How can I fix this? – tlarsin Aug 29 '17 at 23:39

0 Answers0