0

I've run into an issue when trying to access data from an API

I've tried a number of ways to read the info (keys, json array etc) but it doesn't seem to work.

One of the issues seems to be that I need to be able to call the objects by an index rather that a name as the names will differ between json calls.

What I need to be able to is the following.

  1. Please check the json here

  2. I need to be able to access the data highlighted in this image

So essentially i need access to the following in this example

0: > data > 0   > wh > "WH"
0: > data > 273 > wh > "0"
0: > data > 274 > wh > "3" 

What I have at the moment is the following.

JSONObject league_table_data = jsonPart.getJSONObject("data");

Iterator<String> iter = league_table_data.keys();
while (iter.hasNext()) {
String key = iter.next();


try {
   Object value = league_table_data.get(key);
   Toast.makeText(this, value.getString("name"), Toast.LENGTH_SHORT).show();
    } catch (JSONException e) {
            // problem
    }
}
NathW
  • 39
  • 8
  • Also, this might be helpful : [link](https://stackoverflow.com/questions/6773474/json-parsing-to-java-android-application) – veggirice Sep 28 '17 at 21:27
  • "What I have at the moment is the following" -- and what is the problem? IOW, what does "it doesn't seem to work" mean, in programming terms? You cannot call `getString()` on an `Object`, but by changing `get()` to `getJSONObject()`, you will get the nested `JSONObject` and can work with it. – CommonsWare Sep 28 '17 at 21:31

0 Answers0