title: Android Not Sure How To Refer To Value In JSON File (JSON Parsing)
body: <p>Example JSON Page
  <a href="http://maps.googleapis.com/maps/api/geocode/json?latlng=51.155455,-0.165058&amp;sensor=true" rel="nofollow">http://maps.googleapis.com/maps/api/geocode/json?latlng=51.155455,-0.165058&amp;sensor=true</a></p>
  
  <pre><code>@SuppressLint("NewApi")
  public void readAndParseJSON(String in) {
      try {
          JSONObject reader = new JSONObject(in);
          // This works and returns address
          JSONArray resultArry = reader.getJSONArray("results");
          String Address = resultArry.getJSONObject(1).getString("formatted_address").toString();
          Log.e("Address", Address);
          // Trying to get PostCode on code below - this is not working (log says no value at address components)
          JSONArray postCodeArray  = reader.getJSONArray("address_components");
          String postCode =  postCodeArray.getJSONObject(1).getString("long_name").toString();
          Log.e("PostCode", postCode );
  </code></pre>
  
  <p>This code returns the address correctly. How can I get the post code long_name which is inside address_components?</p>
  
  <p><strong>Solution</strong>
  I had to get each array, and then get the post code value.
  I am using the value 7, as that is the JSONObject that has the postcode stored in the "long_name" field.</p>
  
  <pre><code>JSONObject readerJsonObject = new JSONObject(in);
   readerJsonObject.getJSONArray("results");
   JSONArray resultsJsonArray = readerJsonObject.getJSONArray("results");
   JSONArray postCodeJsonArray = resultsJsonArray.getJSONObject(0).getJSONArray("address_components");
   String postCodeString =  postCodeJsonArray.getJSONObject(7).getString("long_name").toString();         
   Log.e("TAG", postCodeString);
  </code></pre>
  
  <p>Hope that helps.</p>