Issue
Im having issues with being able to get the indivisual responses from this JSON Array. Im trying to write some code that will allow me to use the vaules indivisually, as well as how to combine them if i needed too. These responses are always integers.
Java
JSONObject jsonObj = new JSONObject(jsonStr);
data_array = jsonObj.getJSONArray("data");
for (int i = 0; i < data_array.length(); i++) {
JSONObject prod = data_array.getJSONObject(i);
Log.d("Logging Response", prod);
}
Json
[5652,8388,8388,7537,8843,2039,8235,0,12220]
I'd like to figure out how i can add them together and return the calculated result, as well as how to use them individually. such as (prod + prod + prod) etc...
Solution
JSONArray data = jsonObj.getJSONArray("data");
for (int i = 0; i < data.length(); i++) {
Integer prod = (Integer) data.get(i);
System.out.println("Prod " + prod);
// loop and add it to array or arraylist
}
Answered By - Pankaj Kumar