修复了链接,现在我收到 JSON 错误消息
java.lang.ClassCastException: org.json.JSONObject$1 cannot be cast to org.json.JSONObject
显然我的错误在这里的某个地方:
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 > 0) {
for (int i = 0; i < length; i++) {
JSONObject group = (JSONObject) groups.get(i);
JSONArray items = (JSONArray) group.getJSONArray("items");
int ilength = items.length();
for (int j = 0; j < 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);
}
Tomcat消息
10-25 16:37:32.731: I/System.out(12828): https://api.foursquare.com/v2/venues/search? ll=2.94,101.66&client_id=xxxxx&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&client_id=xxxxxxx&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