issue in looping
<p>I am facing issue in looping in the following code,i am passing a list of forms to it,i am not sure what is going wrong,i need the output as but i am getting only the last form_id.I have this code to get this output as ,here i am passing a list of forms and getting the json as output. Please let me know where am i going wrong.</p>

<p>output : </p>

<pre><code>{
    "forms": [
        { "form_id": "1", "form_name": "test1" },
        { "form_id": "2", "form_name": "test2" } 
    ]
}
</code></pre>

<hr>

<p>code :    </p>

<pre><code>public class MyFormToJSONConverter {

   public JSONObject getJsonFromMyFormObject(List&lt;Form&gt; form) {

        JSONObject responseDetailsJson = new JSONObject();
        JSONArray jsonArray = null;
        List&lt;JSONArray&gt; list = new ArrayList&lt;JSONArray&gt;();
        System.out.println(form.size());
        for (int i = 0; i &lt; form.size(); i++) {
               JSONObject formDetailsJson = new JSONObject();
               formDetailsJson.put("form_id", form.get(i).getId());
               formDetailsJson.put("form_name", form.get(i).getName());
               formDetailsJson.put("desc", 
                                    form.get(i).getFormDescription());
               jsonArray = new JSONArray();
               jsonArray.add(formDetailsJson);
               list.add(jsonArray);
        }

        for (JSONArray json : list) {
               responseDetailsJson.put("form", json);
        }

        return responseDetailsJson;
   }
</code></pre>
