从Meetup API中获取此JSON文件中的某些值不起作用

时间:2013-10-25 18:04:06

标签: javascript jquery json api meetup

我正在使用Meetup API。一切似乎都有效,除了我无法从JSON中的item.venue.zip或item.venue.address_1中获取值。

这是我的代码:

$(document).ready(function(){ 
$.getJSON("http://api.meetup.com/2/open_events.json?zip=10001&radius=7&topic=technology&status=upcoming&time=,1w&key=APIKEY&callback=?", function (data) { 
var htmlString = ""; 
$.each(data.results, function (i, item) {
 htmlString += '<h3><a href="' + item.event_url + '" target="_blank">' + item.name + '</a></h3>' + 'People attending: ' + item.yes_rsvp_count + item.time + item.group.name + item.maybe_rsvp_count; }); 
$('#upcoming').html(htmlString);
}); 
});

这就是我的JSON的样子:

?({
"results": [
    {
        "rsvp_limit": 90,
        "status": "upcoming",
        "visibility": "public",
        "maybe_rsvp_count": 0,
        "venue": {
            "id": 15570612,
            "zip": "11215",
            "lon": -73.99025,
            "repinned": false,
            "name": "SNAP Interactive (4th Floor)",
            "state": "NY",
            "address_1": "462 7th Avenue",
            "lat": 40.751926,
            "city": "New York",
            "country": "us"
        },
        "id": "146849412",
        "utc_offset": -14400000,
        "distance": 0.13401024043560028,
        "time": 1382742000000,
        "waitlist_count": 0,
        "updated": 1382447374000,
        "yes_rsvp_count": 83,
        "created": 1382446781000,
        "event_url": "http:\/\/www.meetup.com\/nygraph\/events\/146849412\/",
        "description": "<p><b>For this week’s meetup, Colin Hodge will be speaking about his experiences building Bang With Friends’ recommendation engine and transitioning it over to one using Neo4j, a graph database.<\/b><\/p>\n<p>Launched in January, Bang With Friends has been one of the fastest-growing Facebook apps of this year, scaling rapidly from a hastily thrown-together half-joke to over half a million users in its first two weeks, and in the process becoming a serious player in the dating and social ecosystem.<\/p>\n<p>Colin Hodge co-founded Bang With Friends in January 2013 and has served as CEO since its conception. Previously, Colin founded HeardAboutYou, a dating startup that evolved into Bang With Friends, as well as Cloud 8 Studios, a mobile apps company that published flick+share, a location-based photo sharing app. Colin holds a Bachelor of Science from Cornell University in Computer Science, where he served as Vice President of the local chapter of the Association for Computing Machinery.<\/p>",
        "name": "Graph-based Recommendations at Bang With Friends",
        "headcount": 0,
        "group": {
            "id": 1876871,
            "group_lat": 40.75,
            "name": "NY Graph Meetup",
            "group_lon": -73.98999786376953,
            "join_mode": "open",
            "urlname": "nygraph",
            "who": "Members"
        }
    }
],
"meta": {
    "lon": "\"\"",
    "count": 1,
    "link": "http:\/\/api.meetup.com\/2\/open_events.json",
    "next": "",
    "total_count": 1,
    "url": "http:\/\/api.meetup.com\/2\/open_events.json?key=APIKEY&status=upcoming&radius=1.0&topic=technology&and_text=False&limited_events=False&desc=False&offset=0&callback=%3F&format=json&zip=10001&page=200&time=%2C1d",
    "id": "",
    "title": "Meetup Open Events v2",
    "updated": 1382724786664,
    "description": "Searches for recent and upcoming public events hosted by Meetup groups. Its search window  is the past one month through the next three months, and is subject to change. Open Events is optimized to search for current events by location, category, topic, or text, and only lists Meetups that have **3 or more RSVPs**. The number or results returned with each request is not guaranteed to be the same as the page size due to secondary filtering. If you're looking for a particular event or events within a particular group, use the standard [Events](\/meetup_api\/docs\/2\/events\/) method.",
    "method": "OpenEvents",
    "lat": "\"\""
}
})

再一次,抓住item.status或item.name或item.group.name都可以正常工作,但是一旦尝试抓住item.venue.zip,我就会在控制台中收到这样的错误:

未捕获的TypeError:无法读取未定义的属性“zip”

是什么给出了?

1 个答案:

答案 0 :(得分:1)

更新: 我发现所有数据项都没有“场地”属性(即数据不完整),所以我不得不申请

 if (item.venue)

代码。

另外,我下载了一个chrome扩展程序,当我在浏览器中查看JSON文件时,它有助于更​​好地解析JSON。

:)