2011-12-28 5 views
0

私はアンドロイドで作業しています。私は場所のアドレスのリストを表示したい。私はfoursquareを使ってこの仕事をしています。Android:foursquareインテグレーションを使用して場所アドレスを取得する際にエラーが発生しました

しばらく前に正常に動作しています。今は何らかのエラーを示しています。

これは私が試しているコードです。

public ArrayList<FsqVenue> getNearby(double latitude, double longitude) throws Exception { 
    ArrayList<FsqVenue> venueList = new ArrayList<FsqVenue>(); 

    try { 

     String ll = String.valueOf(latitude) + "," + String.valueOf(longitude); 
     URL url  = new URL(API_URL + "/venues/search?ll=" + ll + "&oauth_token=" + mAccessToken); 

     Log.d(TAG, "Opening URL " + url.toString()); 

     HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); 

     urlConnection.setRequestMethod("GET"); 
     urlConnection.setDoInput(true); 
     urlConnection.setDoOutput(true); 

     urlConnection.connect(); 

     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 < 8; 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.herenow = item.getJSONObject("hereNow").getInt("count"); 
        venue.type  = group.getString("type"); 

        venueList.add(venue); 
       } 
      } 
     } 






    } catch (Exception ex) { 
     throw ex; 
    } 

    return venueList; 
} 

これが発生しているエラーである: -

org.json.JSONException:アドレスなし値 org.json.JSONObject.get(JSONObject.java:354)

ブラウザで使用しているAPIのOUTPUTをチェックアウトしました。このAPIの出力です: -

{"meta":{"code":200,"errorType":"deprecated","errorDetail":"This endpoint will stop returning groups in the future. Please use a current version, see http:\/\/bit.ly\/vywCav."}**,"notifications":[{"type":"notificationTray","item":{"unreadCount":0}}],"response":{"groups":[{"type":"nearby","name":"Nearby","items":[{"id":"4ed0c8f48231b9ef88fe5f09","name":"Banayan Tree School","contact":{},"location":{"lat":26.857693,"lng":75.76603,"distance":524},"categories":[{"id":"4bf58dd8d48988d1a8941735","name":"General College & University","pluralName":"General Colleges & Universities","shortName":"Other - Education","icon":"https:\/\/foursquare.com\/img\/categories\/education\/default.png","parents":["Colleges & Universities"],"primary":true}],"verified":false,"stats":{"checkinsCount":3,"usersCount":3,"tipCount":0},"hereNow":{"count":0}}]}} 

どうすればよいか教えてください。 私はこれがAPIの問題のバージョンに関連していると思います。

答えて

3

二つの問題があります。

  1. APIの使用量は、あなたが持っているリンク(here)で説明したように、要求に& V = {日付}を追加する必要があります。..例:v = 20111228です今日
  2. 例外として、その会場にはアドレス入力がないので、foursquareはjsonレスポンスでそれを返しません。レスポンスを解析するときに、探しているデータがアクセスする前に返されていることを確認します。これはFoursquareから返されるほとんどのデータに当てはまります - それが存在しない場合、応答には含まれません。

したがって、リクエストにvを追加して、データにアクセスする前にそのデータが存在することを確認し、問題を解決する必要があります。

関連する問題