title: how to add all values of JSONObject to JSONArray
body: <p>First, I want to add all <code>ArrayList</code> Values into <code>JsonObject</code> then I want to add these JSON object to <code>JsonArray</code> I have done wright in the first I have added all <code>ArrayList</code> to <code>JsonObject</code> but I can't add all <code>JsonObject</code> to <code>JsonArray</code>.</p>
  
  <p>This is my code to convert json object to json Array:-</p>
  
  <pre><code> submit.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              JSONArray jsonArray = new JSONArray();
  
            JSONObject jsonObject = new JSONObject();
  
              for (int i = 0; i &lt; records.size(); i++) {
                  try {
                      jsonObject.put("sid", records.get(i).getsid());
                      jsonObject.put("name", records.get(i).getpName());
  
  
                      jsonArray.put(jsonObject));
  
  
  
  
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
              }
              Log.e("ATTENDANCE", jsonArray.toString() + "");
          }
  
      });
  </code></pre>
  
  <p>I am getting only the last value of the ArrayList please help me I want The output to be like these</p>
  
  <pre><code>  [
          {
                "student_no":"3924/08",
                "firstname":"olana
          },
          {
                "student_no":"4011/08",
                "firstname":"yallem"
          }
    ]
  </code></pre>