title: Converting ArrayList to JSON - Android
body: <p>I have a Array List and a separate string. i want to convert these into JSON format and expect it below json format.</p>
  
  <p>Expected format,</p>
  
  <pre><code>{  
  "last_sync_date": "2014-06-30 04:47:45",
  "recordset": [
      {
          "contact_group": {
              "guid": "y37845y8y",
              "name": "Family",        
              "description": "Family members",              
              "isDeleted": 0        
          } 
      },
      {
          "contact_group": { 
              "guid": "gt45tergh4",        
              "name": "Office",        
              "description": "Office members",              
              "isDeleted": 0        
          } 
      } 
  ]
  } 
  </code></pre>
  
  <p>i used this way bt it's wrong,</p>
  
  <pre><code>public void createGroupInServer(Activity activity, String lastSyncDateTime, ArrayList&lt;ContactGroup&gt; groups)
          throws JSONException {
  
      // create json object to contact group
      JSONObject syncDateTime = new JSONObject();
      syncDateTime.putOpt("last_sync_date", lastSyncDateTime);
  
      JSONArray jsArray = new JSONArray("recordset");
  
      for (int i=0; i &lt; groups.size(); i++) {
          JSONObject adsJsonObject = new JSONObject("contact_group");
          adsJsonObject = jsArray.getJSONObject(i);
          adsJsonObject.put("guid", groups.get(i).getGroupId());
          adsJsonObject.put("name", groups.get(i).getGroupName());
          adsJsonObject.put("isDeleted", groups.get(i).getIsDeleted());
  }
  </code></pre>
  
  <p>please help.</p>