2014-11-02 88 views
0

我試圖從Foursquare的API中獲取地點列表。到目前爲止這麼好,但我碰到了一堵我無法弄清楚的牆。希望在這裏的人可能有一個好主意。從數組內部的數組中獲取對象

我目前使用的列表顯示了forsquare列表中的場地類型,然後分解了每個場地的名稱和lat/lng。我有的問題是從foursquare得到類別。該類別存儲在陣列內部的另一個陣列中,用於場地。

這是我到目前爲止有:

function app(info) { 
    $('#content').append(info); 
} 

function getinfo(venueAPI) { 
    $.getJSON(venueAPI, function (data) { 
      var arr = []; 
      var venuearr = []; 
       $('#content').empty(); 
       console.log(data); 
       b = '<br/>'; 
       categoryArr = data.response.list.categories.items; 
       categoryArrLength = data.response.list.categories.items.length; 
       console.log(categoryArr); 
       console.log(categoryArrLength); 
       for (var x = 0; x < categoryArrLength; x++) { 
                 app(categoryArr[x].category.pluralName + b); 
                } 
       arr = data.response.list.listItems; 
       venuearr = arr.items; 

       console.log(venuearr); 

       for (var i = 0; i < venuearr.length; i++) { 
                ltlng = L.latLng(venuearr[i].venue.location.lat, venuearr[i].venue.location.lng); 
                $('#content').append(ltlng + b); 
                app(venuearr[i].venue.name + b); 

       } 
    }); 
    getinfo(); 
} 

返回JSON這樣每個場地:

"venue": { 
          "id": "51db2eca498e76d75a5dfea2", 
          "name": "A Gathering Of Stitches", 
          "contact": {}, 
          "location": { 
           "address": "54 Cove St", 
           "lat": 43.66797, 
           "lng": -70.256453, 
           "cc": "US", 
           "city": "Portland", 
           "state": "ME", 
           "country": "United States", 
           "formattedAddress": [ 
            "54 Cove St", 
            "Portland, ME" 
           ] 
          }, 
          "categories": [ 
           { 
            "id": "4bf58dd8d48988d1f4941735", 
            "name": "Design Studio", 
            "pluralName": "Design Studios", 
            "shortName": "Design", 
            "icon": { 
             "prefix": "https://ss3.4sqi.net/img/categories_v2/shops/design_", 
             "suffix": ".png" 
            }, 
            "primary": true 
           } 
          ], 

,這就是得到集團的印刷在屏幕上:

Pubs 
Thrift/Vintage Stores 
Design Studios 
Coffee Shops 
LatLng(43.6565, -70.25313) 
Bull Feeney's 
LatLng(43.65697, -70.25081) 
Andy's Old Port Pub 
LatLng(43.6571, -70.25713) 
Arabica Coffee 
LatLng(43.66797, -70.25645) 
A Gathering Of Stitches 
LatLng(43.65687, -70.25763) 
Find 

我已經嘗試了幾種不同的想法,但目前爲止似乎沒有任何工作。

+0

真的不清楚,我想從類別陣列「名稱」你的問題是 – charlietfl 2014-11-02 22:22:10

+0

。例如,Bull Feeny's是一家酒吧,Arabica Coffee是一家咖啡店等... – 2014-11-02 22:26:09

回答

1
venue.categories[0].name; 

小提琴: http://jsfiddle.net/18kfrek5/

+0

我發誓我試過了,它沒有奏效,但我只是試了一遍,它工作。謝謝 :) – 2014-11-02 22:52:27