noob Android/JSON person here. I hope someone might help me?
I've looked and looked but don't think it's what I'm after. I've been working on this project all day so maybe my brain has just gone to mush... If this has been awnsered else where please point me that way :)
Anyway, I wish to get a specific object from within an JSONArray - here's what's happening so far:
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_obj = jArray.getJSONObject(i);
name = json_obj.getString("txt_title");
}
txt_title.setText(name);
As far as I understand result
returns the entire JSONArray, then I go through the length of those results using the for loop
and get the json objects. At the moment I'm only asking for values from "txt_title"
in the Array. So far, so good?
Then what I want to do is, say only set the third "txt_title"
value from the Array.
At the moment I would expect txt_title.setText(name)
to be displaying ALL the titles in "txt_title"
however it's only displaying the LAST title in the Array. This probably has something to do with the for loop
?
How would I go about choosing which object is displayed?