title: How to parse a two dimensional JSON Object in java
body: <p>This is my JSON data</p>
  
  <pre><code>{
  
      "field1" : [
          {
              "key1" : "1",
              "key2" : "2"
          }, {
              "key1" : "1",
              "key2" : "2",
              "key3" : "3",
              "key4" : "4"
          }
      ],
      "field2" : {
          "key1" : "1",
          "key2" : "2",
          "key3" : "3",
          "key4" : "4",
          "key5" : "5"
      },
      "field3" : {
          "key1" : "1"
      }
  }
  </code></pre>
  
  <p>this is my code</p>
  
  <pre><code>JSONParser jsonParser = new JSONParser();
  JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
  
  Set arr = jsonObject.keySet();
  Iterator iterator = arr.iterator();
  Collection innerArray = jsonObject.values();
  Iterator iterator1 = innerArray.iterator();
  while (iterator.hasNext() &amp;&amp; iterator1.hasNext()) {
      System.out.println("key="+iterator.next().toString());
      System.out.println("value="+ iterator1
              .next().toString());
  }
  </code></pre>
  
  <p>i need output like this</p>
  
  <pre><code>field1
  -------
  key1 --&gt;1
  
  key2 --&gt;2
  
  field1
  ----------
  key1 --&gt;1
  
  key2 --&gt;2
  
  key3 --&gt;3
  
  key4 --&gt;4
  
  
  field2
  --------
  key1 --&gt;1
  
  key2 --&gt;2 
  
  key3 --&gt;3
  
  key4 --&gt;4
  
  key5 --&gt;5
  
  
  field3
  ------
  key1 --&gt; 1
  </code></pre>
  
  <p>Current Output:</p>
  
  <pre><code>key=field3 value={"key1":"1"} 
  
  key=field2 value={"key4":"4","key3":"3","key5":"5","key2":"2","key1":"1"}
  
  key=field1 value=[{"key2":"2","key1":"1"},{"key4":"4","key3":"3","key2":"2","key1":"1"}] 
  </code></pre>
  
  <p>Any idea?</p>