gpt4 book ai didi

javascript - 我如何在我的 JQuery 中应用这个 JSONP api?

转载 作者:行者123 更新时间:2023-11-28 14:50:23 26 4
gpt4 key购买 nike

所以我有这个 Foursquare API..当我在浏览器上点击它时,它会返回 JSON 响应。

https://api.foursquare.com/v2/venues/search?ll=40.7,-74&callback=MY_FUNCTION_NAME

我如何将它包装在 JQuery 中,然后正常使用 JSON 对象?

响应是这样的:

MY_FUNCTION_NAME({"meta":{"code":200},"response":{"groups":[{"type":"nearby","name":"Nearby","items":[{"id":"4b81ea40f964a520e0c330e3","name":"Brooklyn Bridge Park - Pier 1","contact":{},"location":{"address":"334 Furman Street","city":"Brooklyn","state":"NY","postalCode":"11201","lat":40.701984159668676,"lng":-73.9969539642334,"distance":338},"categories":[{"id":"4bf58dd8d48988d163941735","name":"Park","icon":"http://foursquare.com/img/categories/parks_outdoors/default.png","parents":["Parks & Outdoors"],"primary":true}],"verified":false,"stats":{"checkinsCount":3759,"usersCount":2489},"specials":[],"hereNow":{"count":0}},{"id":"42377700f964a52024201fe3","name":"Brooklyn Heights Promenade","contact":{},"location":{"address":"Columbia Heights","crossStreet":"btw Montague and Middagh","city":"Brooklyn","state":"NY","postalCode":"11201","lat":40.69829137715981,"lng":-73.99663209915161,"distance":342},"categories":[{"id":"4bf58dd8d48988d163941735","name":"Park","icon":"http://foursquare.com/img/categories/parks_outdoors/default.png","parents":["Parks & Outdoors"],"primary":true},{"id":"4bf58dd8d48988d1e7941735","name":"Playground","icon":"http://foursquare.com/img/categories/parks_outdoors/playground.png","parents":["Parks & Outdoors"]},{"id":"4bf58dd8d48988d165941735","name":"Scenic Lookout","icon":"http://foursquare.com/img/categories/parks_outdoors/default.png","parents":["Parks & Outdoors"]}],"verified":false,"stats":{"checkinsCount":3364,"usersCount":1422},"specials":[],"hereNow":{"count":0}},{"id":"4c3a5ad83849c92880e0c2b1","name":"Blue Marble Ice Cream","contact":{},"location":{"address":"Brooklyn Bridge Park - Pier 1","city":"Brooklyn","state":"NY","postalCode":"11201","lat":40.70136599888968,"lng":-73.99794101715088,"distance":230},"categories":[{"id":"4bf58dd8d48988d1c9941735","name":"Ice Cream","icon":"http://foursquare.com/img/categories/food/icecream.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":55,"usersCount":41},"specials":[],"hereNow":{"count":0}},{"id":"4c48dc0520ab1b8d6118fd15","name":"Movies With A View","contact":{},"location":{"lat":40.701781,"lng":-73.997748,"distance":274},"categories":[{"id":"4bf58dd8d48988d162941735","name":"Other - Parks & Outdoor","icon":"http://foursquare.com/img/categories/parks_outdoors/default.png","parents":["Parks & Outdoors"],"primary":true}],"verified":false,"stats":{"checkinsCount":93,"usersCount":54},"specials":[],"hereNow":{"count":0}},{"id":"4c3f7d0cff711b8d68fd0e05","name":"75 Wall Street Gym","contact":{},"location":{"city":"New York","state":"New York","lat":40.700821,"lng":-74.001984,"distance":190},"categories":[{"id":"4bf58dd8d48988d176941735","name":"Gym","icon":"http://foursquare.com/img/categories/building/gym.png","parents":["Home / Work / Other","Gym / Fitness"],"primary":true}],"verified":false,"stats":{"checkinsCount":70,"usersCount":30},"specials":[],"hereNow":{"count":0}},{"id":"4b8f057af964a520184533e3","name":"Exchange Hotel","contact":{},"location":{"city":"New York","state":"New York","lat":40.700521,"lng":-74.001527,"distance":141},"categories":[{"id":"4bf58dd8d48988d121941735","name":"Lounge","icon":"http://foursquare.com/img/categories/nightlife/lounge.png","parents":["Nightlife"],"primary":true}],"verified":false,"stats":{"checkinsCount":8,"usersCount":7},"specials":[],"hereNow":{"count":0}},{"id":"4c2cd3d38abca593ac4e0220","name":"The Arena","contact":{},"location":{"city":"New York","state":"New York","lat":40.701164,"lng":-74.001253,"distance":167},"categories":[],"verified":false,"stats":{"checkinsCount":9,"usersCount":2},"specials":[],"hereNow":{"count":0}},{"id":"4c0ad81b009a0f47ff2ceabf","name":"Yeasayer Boat Of ROCK","contact":{},"location":{"city":"Brooklyn","state":"New York","postalCode":"11201","lat":40.697134,"lng":-74.00022,"distance":319},"categories":[{"id":"4bf58dd8d48988d12d951735","name":"Boat / Ferry","icon":"http://foursquare.com/img/categories/travel/boat.png","parents":["Travel"],"primary":true}],"verified":false,"stats":{"checkinsCount":29,"usersCount":27},"specials":[],"hereNow":{"count":0}},{"id":"4c704f0334443704e4cc235f","name":"Spiral Pool","contact":{},"location":{"city":"Brooklyn","state":"New York","postalCode":"11201","lat":40.698981285095215,"lng":-73.99768352508545,"distance":226},"categories":[{"id":"4bf58dd8d48988d165941735","name":"Scenic Lookout","icon":"http://foursquare.com/img/categories/parks_outdoors/default.png","parents":["Parks & Outdoors"],"primary":true}],"verified":false,"stats":{"checkinsCount":11,"usersCount":10},"specials":[],"hereNow":{"count":0}},{"id":"4c67633d8e9120a1d3ddda64","name":"Shroud Park","contact":{},"location":{"address":"Park Place","crossStreet":"Washington","city":"Brooklyn","state":"New York","postalCode":"11238","lat":40.7012193,"lng":-73.9973273,"distance":263},"categories":[{"id":"4bf58dd8d48988d163941735","name":"Park","icon":"http://foursquare.com/img/categories/parks_outdoors/default.png","parents":["Parks & Outdoors"],"primary":true}],"verified":false,"stats":{"checkinsCount":14,"usersCount":13},"specials":[],"hereNow":{"count":0}},{"id":"4c5c631c94fd0f47af7ec845","name":"Shuttle Train","contact":{},"location":{"address":"Park Place","crossStreet":"Franklin avenue","city":"Brooklyn","state":"New York","postalCode":"11216","lat":40.7017332,"lng":-73.9965928,"distance":346},"categories":[{"id":"4bf58dd8d48988d1fd931735","name":"Subway","icon":"http://foursquare.com/img/categories/travel/subway.png","parents":["Travel"],"primary":true}],"verified":false,"stats":{"checkinsCount":19,"usersCount":7},"specials":[],"hereNow":{"count":0}},{"id":"4c0077809cf52d7f4ce013e7","name":"Booze Cruise","contact":{"phone":"2126916693"},"location":{"address":"East 23rd St","crossStreet":"FDR Drive","city":"New York","state":"NY","postalCode":"10010","lat":40.703544,"lng":-74.001143,"distance":406},"categories":[{"id":"4bf58dd8d48988d11f941735","name":"Nightclub / Discotheque","icon":"http://foursquare.com/img/categories/nightlife/danceparty.png","parents":["Nightlife"],"primary":true}],"verified":false,"stats":{"checkinsCount":60,"usersCount":45},"specials":[],"hereNow":{"count":0}},{"id":"4b7c8bedf964a5202c9a2fe3","name":"160 Columbia Heights","contact":{},"location":{"address":"160 Columbia Heights","city":"Brooklyn","state":"NY","lat":40.698296,"lng":-73.996675,"distance":338},"categories":[],"verified":false,"stats":{"checkinsCount":42,"usersCount":4},"specials":[],"hereNow":{"count":0}},{"id":"4c4b1b6b9c8d2d7f9c41826a","name":"Wow House rehearsal space","contact":{},"location":{"address":"Park","crossStreet":"Grand","city":"Brooklyn","state":"NY","lat":40.7012193,"lng":-73.9973273,"distance":263},"categories":[{"id":"4bf58dd8d48988d137941735","name":"Theater","icon":"http://foursquare.com/img/categories/arts_entertainment/default.png","parents":["Arts & Entertainment","Performing Arts"],"primary":true}],"verified":false,"stats":{"checkinsCount":8,"usersCount":5},"specials":[],"hereNow":{"count":0}},{"id":"4d00096e6923721ec97cc23b","name":"My Palatial Estate","contact":{},"location":{"state":"New York","lat":40.70251,"lng":-73.998345,"distance":312},"categories":[],"verified":false,"stats":{"checkinsCount":18,"usersCount":1},"specials":[],"hereNow":{"count":0}},{"id":"4cd38685558a37046ceec1a6","name":"Shawarma truck","contact":{},"location":{"address":"Wall st","crossStreet":"Water st","city":"New York","state":"New York","postalCode":"10005","lat":40.701133,"lng":-73.999322,"distance":138},"categories":[],"verified":false,"stats":{"checkinsCount":4,"usersCount":3},"specials":[],"hereNow":{"count":0}},{"id":"4c4672f91ddec9286aab9a32","name":"Opium Den","contact":{},"location":{"city":"Noen Phoem","state":"Thailand","lat":40.702122,"lng":-73.999742,"distance":237},"categories":[],"verified":false,"stats":{"checkinsCount":6,"usersCount":5},"specials":[],"hereNow":{"count":0}},{"id":"4bf5c1a15e800f47f326e6d4","name":"Fino's","contact":{},"location":{"city":"New York","state":"New York","lat":40.700396,"lng":-74.001432,"distance":128},"categories":[],"verified":false,"stats":{"checkinsCount":4,"usersCount":4},"specials":[],"hereNow":{"count":0}},{"id":"4c90de437f3b8cfa65b7971e","name":"Taxi 4N62","contact":{},"location":{"city":"New York","state":"New York","lat":40.700249,"lng":-74.001442,"distance":124},"categories":[],"verified":false,"stats":{"checkinsCount":3,"usersCount":3},"specials":[],"hereNow":{"count":0}},{"id":"4c7150b8b5a5236a85a35252","name":"Yummy Coffee","contact":{},"location":{"city":"New York","state":"New York","lat":40.702122,"lng":-73.999742,"distance":237},"categories":[],"verified":false,"stats":{"checkinsCount":9,"usersCount":4},"specials":[],"hereNow":{"count":0}},{"id":"4c1d05c6b9f876b0c5dc7c46","name":"NY Brewfest","contact":{},"location":{"lat":40.703053,"lng":-73.998397,"distance":365},"categories":[],"verified":false,"stats":{"checkinsCount":21,"usersCount":18},"specials":[],"hereNow":{"count":0}},{"id":"4c1d046bb4e62d7f43fcdb93","name":"Mannahatta Park","contact":{},"location":{"crossStreet":"South St and Wall St","city":"New York","state":"New York","lat":40.700281,"lng":-74.001472,"distance":128},"categories":[],"verified":false,"stats":{"checkinsCount":9,"usersCount":7},"specials":[],"hereNow":{"count":0}},{"id":"4c48d05e6594be9a1e573d24","name":"I'm The Dude.  So that's what you call me.","contact":{},"location":{"address":"Furman St.","city":"Brooklyn","state":"NY","lat":40.6974964,"lng":-73.9975451,"distance":347},"categories":[{"id":"4bf58dd8d48988d1e4931735","name":"Bowling Alley","icon":"http://foursquare.com/img/categories/arts_entertainment/bowling.png","parents":["Arts & Entertainment"],"primary":true}],"verified":false,"stats":{"checkinsCount":8,"usersCount":7},"specials":[],"hereNow":{"count":0}},{"id":"4c9d583954c8a1cd3424834b","name":"May Barakat's House","contact":{},"location":{"lat":40.702768,"lng":-73.997328,"distance":381},"categories":[],"verified":false,"stats":{"checkinsCount":22,"usersCount":3},"specials":[],"hereNow":{"count":0}},{"id":"4c8191582f1c236a8e5e3143","name":"Brooklyn Promenade","contact":{},"location":{"city":"New York","state":"New York","lat":40.702858,"lng":-73.998399,"distance":345},"categories":[],"verified":false,"stats":{"checkinsCount":27,"usersCount":26},"specials":[],"hereNow":{"count":0}},{"id":"4c6aba8f35d3be9ad5922206","name":"Taxi 7L20","contact":{},"location":{"city":"New York","state":"New York","lat":40.700696,"lng":-74.001889,"distance":177},"categories":[],"verified":false,"stats":{"checkinsCount":1,"usersCount":1},"specials":[],"hereNow":{"count":0}},{"id":"4cb8e3a34c60a0938d643cca","name":"Taxi 5K43","contact":{},"location":{"lat":40.700249,"lng":-74.001442,"distance":124},"categories":[],"verified":false,"stats":{"checkinsCount":1,"usersCount":1},"specials":[],"hereNow":{"count":0}},{"id":"4c391bda2c8020a1ed2c8c00","name":"Angel's","contact":{},"location":{"city":"New York","state":"New York","lat":40.702607,"lng":-73.997774,"distance":345},"categories":[],"verified":false,"stats":{"checkinsCount":5,"usersCount":4},"specials":[],"hereNow":{"count":0}},{"id":"4c8a96439ef0224bf43e5c7b","name":"99 WALL ST","contact":{},"location":{"address":"99 wall st","state":"ny","lat":40.702768,"lng":-73.997328,"distance":381},"categories":[],"verified":false,"stats":{"checkinsCount":5,"usersCount":5},"specials":[],"hereNow":{"count":0}},{"id":"4cf6d622dc40a35dfd244a54","name":"Andy Wu's Bat Cave","contact":{},"location":{"lat":40.70251,"lng":-73.998345,"distance":312},"categories":[],"verified":false,"stats":{"checkinsCount":3,"usersCount":1},"specials":[],"hereNow":{"count":0}}]}]}});

最佳答案

您可以使用 jsonp 格式使其在这里工作

$.getJSON("https://api.foursquare.com/v2/venues/search?ll=40.7,-74&callback=?",
{
format: "json"
},
function(data) {
alert(data)
});

我记不清了,但 format:jsonp 可能是可选的,因为您已经执行了 callback=?

关于javascript - 我如何在我的 JQuery 中应用这个 JSONP api?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4685398/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com