title: Java unable to parse nested json object
body: <p>Below is some sample code:</p>
  <pre><code>import org.json.JSONObject;
  
  String k = &quot;{\&quot;root1\&quot;:\&quot;{\\\&quot;key1\\\&quot;:\\\&quot;val1\\\&quot;,\\\&quot;key2\\\&quot;:1,\\\&quot;key3\\\&quot;:null}\&quot;,\&quot;root2\&quot;:\&quot;OTHERS\&quot;,\&quot;root3\&quot;:1}&quot;;
  JSONObject obj = new JSONObject(str);
  System.out.println(obj);
  
  /* 
  here I want to do something like:
  JSONObject innerObj = (JSONObject) obj.get(&quot;root1&quot;);
  String k1 = innerObj.get(&quot;key1&quot;);
  
  Also, should work with nested inner objects, so for example, should be able to do:
  String k4 = innerObj.get(&quot;key1.innerKey1&quot;);
  */
  </code></pre>
  <pre><code>{&quot;root1&quot;:&quot;{\&quot;key1\&quot;:\&quot;val1\&quot;,\&quot;key2\&quot;:1,\&quot;key3\&quot;:null}&quot;,&quot;root2&quot;:&quot;OTHERS&quot;,&quot;root3&quot;:1}
  </code></pre>
  <p>On doing JSONObject innerObj = (JSONObject) obj.get(&quot;root1&quot;); - it gives:</p>
  <p>Exception in thread &quot;main&quot; java.lang.ClassCastException: java.lang.String cannot be cast to org.json.JSONObject</p>
  <p>I tried Gson, JSONParser - but still unable to do it ...</p>
  <p>Note: Parsing of string 'k' works fine, as the obj is populated correctly and is printed out. It fails when I try to access objects within this obj:
  JSONObject innerObj = (JSONObject) obj.get(&quot;root1&quot;);</p>