I'm working with the Meetup API. All seems to work, except I can't grab the value from item.venue.zip or item.venue.address_1 from the JSON.
This is my code:
$(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);
});
});
This is what my JSON looks like:
?({
"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": "\"\""
}
})
Again, grabbing item.status or item.name or item.group.name all work fine, but as soon as try grabbing item.venue.zip I get an error like this in the console:
Uncaught TypeError: Cannot read property 'zip' of undefined
What gives?
UPDATE: I figured out that the "venue" property didn't exist for all the data items (i.e. there was incomplete data), so I had to apply an
if (item.venue)
to the code.
Also, I downloaded a chrome extension which helped parse the JSON a little bit better when I was viewing the JSON file in my browser.
:)