title: How can I iterate JSONObject to get individual items
body: <p>This is my below code from which I need to parse the <code>JSONObject</code> to get individual items. This is the first time I am working with JSON. So not sure how to parse <code>JSONObject</code> to get the individual items from <code>JSONObject</code>.</p>
  
  <pre><code>try {
      String url = service + version + method + ipAddress + format;
      StringBuilder builder = new StringBuilder();
      httpclient = new DefaultHttpClient();
      httpget = new HttpGet(url);
      httpget.getRequestLine();
      response = httpclient.execute(httpget);
      HttpEntity entity = response.getEntity();
      if (entity != null) {
          InputStream inputStream = entity.getContent();
          bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
          for (String line = null; (line = bufferedReader.readLine()) != null;) {
              builder.append(line).append("\n");
          }
          JSONObject jsonObject = new JSONObject(builder.toString());
          // Now iterate jsonObject to get Latitude,Longitude,City,Country etc etc.
  
      }
  
  } catch (Exception e) {
      getLogger().log(LogLevel.ERROR, e.getMessage());
  } finally {
      bufferedReader.close();
      httpclient.getConnectionManager().shutdown();
  }
  </code></pre>
  
  <p>My JSON looks like this:</p>
  
  <pre><code>{
      "ipinfo": {
          "ip_address": "131.208.128.15",
          "ip_type": "Mapped",
          "Location": {
              "continent": "north america",
              "latitude": 30.1,
              "longitude": -81.714,
              "CountryData": {
                  "country": "united states",
                  "country_code": "us"
              },
              "region": "southeast",
              "StateData": {
                  "state": "florida",
                  "state_code": "fl"
              },
              "CityData": {
                  "city": "fleming island",
                  "postal_code": "32003",
                  "time_zone": -5
              }
          }
      }
  }
  </code></pre>
  
  <p>I need to get <code>latitude</code>, <code>longitude</code>, <code>city</code>, <code>state</code>, <code>country</code>, <code>postal_code</code> from the above object. Can anyone provide any suggestion how to do it efficiently?</p>