There is a code for getting json objects, you need to calculate the sum of all elements from the received one, but I don’t understand how to register the cycle correctly.

StringRequest request = new StringRequest(Request.Method.POST, select_all, new Response.Listener<String>() { @Override public void onResponse(String response) { try { JSONObject jsonObject = new JSONObject(response); JSONArray jsonArray = jsonObject.getJSONArray("image_info_table"); for(int i=0;i<jsonArray.length();i++){ JSONObject info = jsonArray.getJSONObject(i); Item item=new Item(); item.setItem_name_Cart(info.getString("name")); item.setImage(info.getString("path")); item.setQuantity(info.getString("quantity")); item.setPrice(info.getString("price")); item.setSpinner_size(info.getString("size")); array.add(item); int sum; sum=Integer.parseInt(info.getString("price")); for (int b=0; \\ ){ \\вот тут загвоздка } } 

    1 answer 1

     int sum = 0; for(int i = 0; i < jsonArray.length(); i++) { ... sum = sum + Integer.parseInt(info.getString("price")); } // sum has the total value 
    • Thank you) And then the second cycle began to flog) - Romik romikromik