title: how to create multiple JSON Object dynamically?
body: <p>I am trying to insert data into multiple JSON objects but I don't know how to create them dynamically in android. </p>
  
  <p>In the hard coded way it is something like:-</p>
  
  <pre><code>JSONArray pdoInformation = new JSONArray();
  
  JSONObject pDetail1 = new JSONObject();
  JSONObject pDetail2 = new JSONObject();
  JSONObject pDetail3 = new JSONObject();
  
  pDetail1.put("productid", 1);
  pDetail1.put("qty", 3);
  pDetail1.put("listprice", 9500);
  
  pDetail2.put("productid", 2);
  pDetail2.put("qty", 4);
  pDetail2.put("listprice", 8500);
  
  pDetail3.put("productid", 3);
  pDetail3.put("qty", 2);
  pDetail3.put("listprice", 1500);
  
  pdoInformation.put(pDetail1);
  pdoInformation.put(pDetail2);
  pdoInformation.put(pDetail3);
  </code></pre>
  
  <p><strong>But I want to create these <code>JSONObject</code> dynamically as I don't know how many of them are going to be needed while coding and in those dynamically created  <code>JSONObject</code> the data will be filled from three <code>ArrayList</code> of <code>productid</code>, <code>qty</code> and <code>listprice</code>.</strong> </p>
  
  <p><em>So its obvious that the number of those dynamically created <code>JSONObject</code> will depend on the <code>size</code> of any one <code>ArrayList</code>.</em></p>
  
  <p><code>ArrayList</code> :-</p>
  
  <pre><code>ArrayList&lt;String&gt; productid = new ArrayList&lt;String&gt;();
  ArrayList&lt;String&gt; qty = new ArrayList&lt;String&gt;();
  ArrayList&lt;String&gt; listprice= new ArrayList&lt;String&gt;();
  </code></pre>