I want to parse a JSONArray that contains JSONObjects that have no names and whose (index int) positions within the array changes every week or so. I have attempted to parse a particular Object by it’s attributes, but my parser only returns the last Object in the array.
How can i stop my loop when it reaches the object i want to parse and determine the int index of the object for further parsing.
try {
JSONArray jArray = JSONthing.getJSONfromURL("http://something.com");
String attributeiwant = "abc";
for (int i = 0; i < jArray.length(); i++) {
JSONObject alpha = jArray.getJSONObject(i);
String attributeparsed = alpha.getString("widget");
if (attributeparsed == attributeiwant) {
//determine int index of object, so i can parse other attributes
//from same object
}
}
} catch (Exception e) {
Log.e("log_tag", "Error parsing data "+ e.toString());
}
use String.equals for comparing Strings instead of ==