title: Android JSON Parsing getJSONObject
body: <p>Could anyone guide me on this? I'm trying to parse some objects into my JSONArray. But my JSON file is a bit complicated. I'm trying to get the <strong>title</strong>, <strong>description</strong> and the <strong>thumbnail</strong></p>
  
  <p>My JSON FILE </p>
  
  <pre><code>  {
   "query": {
    "count": 1,
    "created": "2013-05-13T17:22:38Z",
    "lang": "en-US",
    "results": {
     "json": {
      "kind": "books#volumes",
      "totalItems": "1145",
      "items": [
       {
        "kind": "books#volume",
        "id": "2_3AjlqS2DMC",
        "etag": "t6birOoou5k",
        "selfLink": "https://www.googleapis.com/books/v1/volumes/2_3AjlqS2DMC",
        "volumeInfo": {
         "title": "Introducing Android Development with Ice Cream Sandwich",
         "authors": [
          "Shane Conder",
          "Lauren Darcey"
         ],
         "publisher": "Addison-Wesley Professional",
         "publishedDate": "2011-10-31",
         "description": "The Android platform continues to aggressively grow in market share against competing mobile platforms, such as Apple iOS and BlackBerry. Android's latest major platform update, Android 4.0, frequently called by its code-name, Ice Cream Sandwich or just ICS merges the smartphone-centric Android 2.3.x (Gingerbread) and the tablet-centric Android 3.x (Honeycomb) platform editions into a single SDK for all smart-devices, be they phones, tablets, televisions, or toasters. This short e-book provides an overview from the authors on the importance of Ice Cream Sandwich as well as key preview content from the upcoming book, \"Android Wireless Application Development, Third Edition, Volume I.\" This preview content provides some essential references, updated for Android SDK 4.0, for those interested in jumping into Android application development at this exciting time. To use this e-book most effectively, you need to download the Android development SDK and tools, install them on your development machine, and configure them using the development environment of your choice. You can find instructions for installing and configuring your computer for Android software development on the Android Developer website at http://d.android.com/sdk/.",
         "industryIdentifiers": [
          {
           "type": "ISBN_10",
           "identifier": "0132947595"
          },
          {
           "type": "ISBN_13",
           "identifier": "9780132947596"
          }
         ],
         "pageCount": "96",
         "printType": "BOOK",
         "categories": "Computers",
         "averageRating": "3.0",
         "ratingsCount": "4",
         "contentVersion": "0.1.0.0.preview.3",
         "imageLinks": {
          "smallThumbnail": "http://bks7.books.google.com/books?id=2_3AjlqS2DMC&amp;printsec=frontcover&amp;img=1&amp;zoom=5&amp;edge=curl&amp;source=gbs_api",
          "thumbnail": "http://bks7.books.google.com/books?id=2_3AjlqS2DMC&amp;printsec=frontcover&amp;img=1&amp;zoom=1&amp;edge=curl&amp;source=gbs_api"
         },
         "language": "en",
         "previewLink": "http://books.google.com/books?id=2_3AjlqS2DMC&amp;printsec=frontcover&amp;dq=android&amp;hl=&amp;cd=2&amp;source=gbs_api",
         "infoLink": "http://books.google.com/books?id=2_3AjlqS2DMC&amp;dq=android&amp;hl=&amp;source=gbs_api",
         "canonicalVolumeLink": "http://books.google.com/books/about/Introducing_Android_Development_with_Ice.html?hl=&amp;id=2_3AjlqS2DMC"
        },
        "saleInfo": {
         "country": "MY",
         "saleability": "NOT_FOR_SALE",
         "isEbook": "false"
        },
        "accessInfo": {
         "country": "MY",
         "viewability": "PARTIAL",
         "embeddable": "true",
         "publicDomain": "false",
         "textToSpeechPermission": "ALLOWED_FOR_ACCESSIBILITY",
         "epub": {
          "isAvailable": "true",
          "acsTokenLink": "http://books.google.com/books/download/Introducing_Android_Development_with_Ice-sample-epub.acsm?id=2_3AjlqS2DMC&amp;format=epub&amp;output=acs4_fulfillment_token&amp;dl_type=sample&amp;source=gbs_api"
         },
         "pdf": {
          "isAvailable": "true",
          "acsTokenLink": "http://books.google.com/books/download/Introducing_Android_Development_with_Ice-sample-pdf.acsm?id=2_3AjlqS2DMC&amp;format=pdf&amp;output=acs4_fulfillment_token&amp;dl_type=sample&amp;source=gbs_api"
         },
         "webReaderLink": "http://books.google.com/books/reader?id=2_3AjlqS2DMC&amp;hl=&amp;printsec=frontcover&amp;output=reader&amp;source=gbs_api",
         "accessViewStatus": "SAMPLE"
        },
        "searchInfo": {
         "textSnippet": "This short e-book provides an overview from the authors on the importance of Ice Cream Sandwich as well as key preview content from the upcoming book, &amp;quot;Android Wireless Application Development, Third Edition, Volume I.&amp;quot; This preview content ..."
        }
       },
       {
        "kind": "books#volume",
        "id": "ASmO8r7i93sC",
        "etag": "tXvdPFo+cKk",
        "selfLink": "https://www.googleapis.com/books/v1/volumes/ASmO8r7i93sC",
        "volumeInfo": {
         "title": "Android Essentials",
         "authors": "Chris Haseman",
         "publisher": "Apress",
         "publishedDate": "2008-08-01",
         "description": "Android Essentials is a no–frills, no–nonsense, code–centric run through the guts of application development on Google’s Mobile OS. This book uses the development of a sample application to work through topics, focusing on giving developers the essential tools and examples required to make viable commercial applications work. Covering the entirety of the Android catalog in less than 150 pages is simply impossible. Instead, this book focuses on just four main topics: the application life cycle and OS integration, user interface, location–based services, and networking. Thorough, complete, and useful work on the nuts and bolts of application development in Android Example driven and practically minded A tool for hobbyists and professionals who want to create production–quality applications What you’ll learn Understand how an Android application functions and communicates with the handset that hosts it. Comprehend the complexities of timers, services, and multimedia playback. Create and display a rich mix of custom–rendered screens and tailored Android widgets. Understand how location–based services are becoming more and more important in the mobile world. See how to use Google’s powerful Map tool. Explore the intricacies of network connectivity in the mobile world. Who this book is for This book is for professional software engineers looking to move their ideas and applications into the mobile space with Android. The author assumes the reader has a passable understanding of Java. They should be able to write classes and handle basic inheritance structures. This book also targets hobbyist developers looking to negotiate the complex minefield of mobile software. Table of Contents Introduction The Application User Interface Location, Location, Location Taking Android Out for a Walk Tying on a Bow",
         "industryIdentifiers": [
          {
           "type": "ISBN_10",
           "identifier": "143021063X"
          },
          {
           "type": "ISBN_13",
           "identifier": "9781430210634"
          }
         ],
         "pageCount": "100",
         "printType": "BOOK",
         "categories": "Computers",
         "averageRating": "1.5",
         "ratingsCount": "3",
         "contentVersion": "preview-1.0.0",
         "imageLinks": {
          "smallThumbnail": "http://bks7.books.google.com/books?id=ASmO8r7i93sC&amp;printsec=frontcover&amp;img=1&amp;zoom=5&amp;edge=curl&amp;source=gbs_api",
          "thumbnail": "http://bks7.books.google.com/books?id=ASmO8r7i93sC&amp;printsec=frontcover&amp;img=1&amp;zoom=1&amp;edge=curl&amp;source=gbs_api"
         },
         "language": "en",
         "previewLink": "http://books.google.com/books?id=ASmO8r7i93sC&amp;printsec=frontcover&amp;dq=android&amp;hl=&amp;cd=3&amp;source=gbs_api",
         "infoLink": "http://books.google.com/books?id=ASmO8r7i93sC&amp;dq=android&amp;hl=&amp;source=gbs_api",
         "canonicalVolumeLink": "http://books.google.com/books/about/Android_Essentials.html?hl=&amp;id=ASmO8r7i93sC"
        },
        "saleInfo": {
         "country": "MY",
         "saleability": "NOT_FOR_SALE",
         "isEbook": "false"
        },
        "accessInfo": {
         "country": "MY",
         "viewability": "PARTIAL",
         "embeddable": "true",
         "publicDomain": "false",
         "textToSpeechPermission": "ALLOWED",
         "epub": {
          "isAvailable": "false"
         },
         "pdf": {
          "isAvailable": "true"
         },
         "webReaderLink": "http://books.google.com/books/reader?id=ASmO8r7i93sC&amp;hl=&amp;printsec=frontcover&amp;output=reader&amp;source=gbs_api",
         "accessViewStatus": "SAMPLE"
        },
        "searchInfo": {
         "textSnippet": "Android Essentials is a no–frills, no–nonsense, code–centric run through the guts of application development on Google’s Mobile OS. This book uses the development of a sample application to work through topics, focusing on giving ..."
        }
       }
      ]
     }
    }
   }
  }
  </code></pre>
  
  <p>My Attempt</p>
  
  <pre><code>try {       
      JSONObject jsonobject = JSONfunctions.getJSONfromURL("MYURL");
      JSONObject json_query = jsonobject.getJSONObject("query");
      JSONObject json_results = json_query.getJSONObject("results");
      JSONObject json_json_result = json_results.getJSONObject("json");
      JSONArray jsonarray = json_json_result.getJSONArray("results");
  
      for (int i = 0; i &lt; jsonarray.length(); i++) {
          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
          json_json_result = jsonarray.getJSONObject(i);
  
          map.put("title", json_json_result.getString("title"));
          map.put("description", json_json_result.getString("description"));
          map.put("thumbnail", json_json_result.getString("thumbnail"));
  
          arraylist.add(map);
      }
  } catch (JSONException e) {
      Log.e("Error", e.getMessage());
      e.printStackTrace();
  }
  </code></pre>
  
  <p>LogCat :</p>
  
  <pre><code>05-13 15:46:50.762: E/Error(2268): No value for results
  05-13 15:46:50.762: W/System.err(2268): org.json.JSONException: No value for results
  05-13 15:46:50.762: W/System.err(2268):     at org.json.JSONObject.get(JSONObject.java:354)
  05-13 15:46:50.762: W/System.err(2268):     at org.json.JSONObject.getJSONArray(JSONObject.java:544)
  </code></pre>
  
  <p>NEW EDIT </p>
  
  <pre><code>try {
  
                  JSONObject json_data = JSONfunctions.getJSONfromURL(url);
                  JSONObject json_query = json_data.getJSONObject("query");
                  JSONObject json_results = json_query.getJSONObject("results");
                  JSONObject json_json_result = json_results.getJSONObject("json");
                  JSONArray json_result = json_json_result.getJSONArray("items");
                  //JSONArray json_result = json_json_resultitem.getJSONArray("volumeInfo");
  
  
                  for (int i = 0; i &lt; json_result.length(); i++) {
                      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
                      JSONObject c = json_result.getJSONObject(i);
                      //map.put("title", c.getString("title").toString());
                      map.put("description", c.optString("title"));
                      arraylist.add(map);
                  }
  </code></pre>
  
  <p>I'm getting NULL when I try to grab title or description. I couldnt use 2 arrays "items" and "volumeInfo"</p>