The data is unknown amounts of JSONobjects, I'd like to capture three data, NAME, LONGITUDE and LATITUDE into the Arraylist.
This is the result of the following code.
wrapall:[[title1, longitude1, latitude1, title2, longitude2, latitude2, title3, longitude3, latitude3, title4,.......]]
But this is what I expect.
wrapall:[[title1, longitude1, latitude1],[title2, longitude2, latitude2],[title3, longitude3, latitude3],.......]
What should be done to change the format like this?
private ArrayList<ArrayList<String>> wrapall =new ArrayList<>();
private ArrayList<String> transthree = new ArrayList<>();
private void parserJson(JSONArray jsonArray) {
try {
JSONArray array = jsonArray;
Log.d("jsonarrayishere", array.toString());
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
String title = object.getString("NAME");
String longitude = object.get("LONGITUDE").toString();
String latitude = object.get("LATITUDE").toString();
transthree.add(title);
transthree.add(longitude);
transthree.add(latitude);
}
wrapall.add(transthree);
transthree = new ArrayList<>();
Log.d("transthree",transthree.toString());
Log.d("wrapall", wrapall.toString());
} catch (JSONException e) {
e.printStackTrace();
Log.d("objectstestwrong", e.getLocalizedMessage());
}
}