title: Getting places from Foursquare API
body: <p>Fixed the link, now I get a JSON error msg</p>
  
  <pre><code> java.lang.ClassCastException: org.json.JSONObject$1 cannot be cast to org.json.JSONObject
  </code></pre>
  
  <p>Apparently my error lies somewhere here:</p>
  
  <pre><code>String response     = streamToString(urlConnection.getInputStream());
          JSONObject jsonObj  = (JSONObject) new JSONTokener(response).nextValue();             
          JSONArray groups    = (JSONArray) jsonObj.getJSONObject("response").getJSONArray("groups");
  
          int length          = groups.length();
          if (length &gt; 0) {                
              for (int i = 0; i &lt; length; i++) {                    
                  JSONObject group    = (JSONObject) groups.get(i);                    
                  JSONArray items     = (JSONArray) group.getJSONArray("items");                     
                  int ilength         = items.length();                     
                  for (int j = 0; j &lt; ilength; j++) {                        
                      JSONObject item = (JSONObject) items.get(j);                         
                      FsqVenue venue  = new FsqVenue();                         
                      venue.id        = item.getString("id");                        
                      venue.name      = item.getString("name");                         
                      JSONObject location = (JSONObject) item.getJSONObject("location");                         
                      Location loc    = new Location(LocationManager.GPS_PROVIDER);                         
                      loc.setLatitude(Double.valueOf(location.getString("lat")));                        
                      loc.setLongitude(Double.valueOf(location.getString("lng")));                         
                      venue.location  = loc;                        
                      venue.address   = location.getString("address");                        
                      venue.distance  = location.getInt("distance");                        
                      venue.type      = group.getString("type");                         
                      VenueList.add(venue);
                      }
  </code></pre>
  
  <p>tomcat message</p>
  
  <pre><code>10-25 16:37:32.731: I/System.out(12828): https://api.foursquare.com/v2/venues/search?            ll=2.94,101.66&amp;client_id=xxxxx&amp;client_secret=xxxxxxx
  
  
  10-25 16:37:32.731: D/FoursquareApi(12828): OPening URLhttps://api.foursquare.com/v2/venues/search?ll=2.94,101.66&amp;client_id=xxxxxxx&amp;client_secret=xxxxxxx
  10-25 16:37:34.645: W/System.err(12828): java.lang.ClassCastException: org.json.JSONObject$1 cannot be cast to org.json.JSONObject
  10-25 16:37:34.645: W/System.err(12828):    at com.example.reddot.Foursquare.getNearby(Foursquare.java:57)
  10-25 16:37:34.653: W/System.err(12828):    at com.example.reddot.MainActivity$LoadPlaces.doInBackground(MainActivity.java:466)
  10-25 16:37:34.653: W/System.err(12828):    at com.example.reddot.MainActivity$LoadPlaces.doInBackground(MainActivity.java:1)
  10-25 16:37:34.653: W/System.err(12828):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
  10-25 16:37:34.653: W/System.err(12828):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  10-25 16:37:34.653: W/System.err(12828):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  10-25 16:37:34.661: W/System.err(12828):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
  10-25 16:37:34.661: W/System.err(12828):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
  10-25 16:37:34.661: W/System.err(12828):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
  10-25 16:37:34.661: W/System.err(12828):    at java.lang.Thread.run(Thread.java:856)
  10-25 16:37:34.661: I/System.out(12828): errorjava.lang.ClassCastException: org.json.JSONObject$1 cannot be cast to org.json.JSONObject
  </code></pre>