Grabbing a key from an API that uses an array. (ANDROID STUDIO)

Viewed 25

I'm trying to grab the "title" in the API but it's in an array. What would I need to change my code to, to be able to grab the "title" in the JSON? I can easily get it to grab the entire JSON by doing "top" instead of "title", but it's the title that I need. Thanks!

API information that needs to be grabbed. ("title"): API information that needs to be grabbed. ("title")

This is my code:

void readJSONTitle(String rawJSON) {
    runOnUiThread(new Runnable() {
        @Override
        public void run(){
            try {
                JSONArray arr = new JSONArray(rawJSON);
                JSONObject jObj = arr.getJSONObject(0);
                String top = jObj.getString("title");
                setFact(top);
            } catch(JSONException e){
                e.printStackTrace();
            }
        }
    })
}
0 Answers
Related