title: count key value in JSON and extract values
body: <p>I have following JSONObject (not array, which I don't mind to convert). I am trying to do two things:</p>
  
  <ol>
  <li><p>get the count of genre entry as "poetry" (count = 2).</p></li>
  <li><p>get the key value of author name and genre:</p>
  
  <ul>
  <li>authorName = malcolm         </li>
  <li><p>genreName = newsarticle</p></li>
  <li><p>authorName = keats        </p></li>
  <li>genreName = poetry</li>
  </ul></li>
  </ol>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>{ "AddressBook" :{
  
  "Details" :{
  "authorname" :{
  
  "Author-malcolm":{
  "genre" :"poetry"
  }
  
  "Author-keats":{
  "genre" :"poetry"
  }
  
  }
  
  }
  }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Code which I tried:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>  public static void main(String[] args) throws Exception, IOException, ParseException {
  
      JSONParser parser = new JSONParser();
      
          Object obj = parser.parse(new FileReader("My path to JSON"));
      
          JSONObject jsonObject = (JSONObject) obj;
          JSONArray arrayhere = new JSONArray();
          arrayhere.add(obj);
          System.out.println(arrayhere);             
          int count = 0;
          for(int i = 0; i &lt; arrayhere.size(); i++) {
            JSONObject element = arrayhere.getJSONObject(i);//The method getJSONObject(int) is undefined for the type JSONArray
            String branchName = element.getString("genre");//The method getString(String) is undefined for the type JSONObject
            if(branchName.equals("poetry")) {
              count ++;
            }
          }
          System.out.println("Count f0r poetry genre=" + count);
      } 
       
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have looked at solutions all over. There is no question similar to this at stackoverflow. I am not sure if the procedure is correct.</p>