1

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' を読み取れません

何を与える?

4

1 に答える 1

1

更新: すべてのデータ項目に対して「会場」プロパティが存在しない (つまり、不完全なデータがあった) ことがわかったので、

 if (item.venue)

コードに。

また、ブラウザーで JSON ファイルを表示しているときに、JSON の解析を少し改善するのに役立つ chrome 拡張機能をダウンロードしました。

:)

于 2013-10-30T02:09:48.237 に答える