title: Use JSON Array inside JSON object in Java
body: <p>I have Array list with integer values from 2 to 6, and I test if each number is odd or even as following:</p>
  
  <pre><code>JSONObject outerObject = new JSONObject();
  JSONArray outerArray = new JSONArray();
  JSONObject [] innerObject = new JSONObject[list1.size()];
          for ( i = 0; i &lt; list1.size(); i++)// change to list1.size()
              {
                  innerObject[i]=new JSONObject();
                  innerObject[i].put("Item" , list1.get(i));
                  if(list1.get(i)%2==0)
                  {
                      innerObject[i].put("Odd or Even", "number "+list1.get(i)+" is even");
                  }
                  else
                      innerObject[i].put("Odd or Even", "number "+list1.get(i)+" is odd");                  
                  outerArray.put(innerObject[i]);
              }
          outerObject.put("rows", outerArray);
          return outerObject.toString();
  </code></pre>
  
  <p>then I have the following JSON file results </p>
  
  <pre><code>{"rows":[
  {"Item":2,"Odd or Even":"number 2 is even"},
  {"Item":3,"Odd or Even":"number 3 is odd"},
  {"Item":4,"Odd or Even":"number 4 is even"},
  {"Item":5,"Odd or Even":"number 5 is odd"},
  {"Item":6,"Odd or Even":"number 6 is even"}
  ]}
  </code></pre>
  
  <p>now I want to find the multiplication between the array list item
  like:</p>
  
  <pre><code>{"rows":[
      {"Item":2,"Odd or Even":"number 2 is even", "Multiplication:[4,6]"},
      {"Item":3,"Odd or Even":"number 3 is odd","Multiplication:[6]"},
      {"Item":4,"Odd or Even":"number 4 is even"},
      {"Item":5,"Odd or Even":"number 5 is odd"},
      {"Item":6,"Odd or Even":"number 6 is even"}
      ]}
  </code></pre>
  
  <p>I know that I need to use another for loop inside the first loop, something like this</p>
  
  <pre><code>for (j=i; j &lt; list1.size(); j++)
              {
                  inerArray[j]=new JSONArray();
                  if (list1.get(j)%list.get(i)==0)
                      inerArray[j].put(list1.get(j));
  
              }
  innerObject[i].put("Multiplication" , inerArray);
  </code></pre>
  
  <p>but it does not work</p>
  
  <p>I'm using Java and Restful web service</p>