所以我正在尝试使用 $.JSON 来获取和访问来自这个 url 的数据以用于一个辅助项目:https ://api.pinterest.com/v2/users/cssquirrel/ 。从访问它可以看出,它是一个有效的 JSON 对象。
所以我使用 jQuery 执行以下 JSONP 请求。
$.getJSON('https://api.pinterest.com/v2/users/cssquirrel/?callback=?', function(data) { callback(data); });`
当我运行它时,我收到错误“无效标签”,因为虽然我收到了包含所有 JSON 信息的响应,但它没有将其包装在回调函数中,这会导致一切都失败。
这是回应:
{"status": "success", "user": {"username": "cssquirrel", "website": "", "about": "", "twitter_link": "", "publish_timeline": false, "is_following": false, "facebook_link": "http://www.facebook.com/cssquirrel", "image_url": "http://media-cache.pinterest.com/avatars/cssquirrel_1332472797.jpg", "location": "", "full_name": "Kyle Weems", "stats": {"followers_count": 10, "likes_count": 13, "pins_count": 259, "following_count": 24, "boards_count": 2}, "id": "123778827166945150", "image_large_url": "http://media-cache.pinterest.com/avatars/cssquirrel_1332472797_o.jpg"}, "boards": [{"category": "home", "is_collaborator": false, "user_id": "187251434415197561", "description": "This board is specifically for things we want to buy or am going to buy for redecorating our apartment in the next year or so (one can hope).", "url": "/jnaepalm/my-apartment-redecoration/", "is_following": false, "thumbnails": ["/uploads/cover_187251365695749104_187251296976783278_8e1oaKi9_1333652274.jpg", "http://media-cache.pinterest.com/upload/187251296976877180_C8VMZpRi_t.jpg", "http://media-cache.pinterest.com/upload/187251296976832689_ripauAtd_t.jpg", "http://media-cache.pinterest.com/upload/187251296976832240_fUHOQFUL_t.jpg", "http://media-cache.pinterest.com/upload/89509111314068749_b8HECGS4_t.jpg", "http://media-cache.pinterest.com/upload/187251296976813631_mqrILJ7L_t.jpg"], "stats": {"followers_count": 53, "pins_count": 11}, "id": "187251365695749104", "name": "My Apartment Redecoration"}, {"category": "architecture", "is_collaborator": false, "user_id": "123778827166945150", "description": "", "url": "/cssquirrel/dawww/", "is_following": false, "thumbnails": ["http://media-cache.pinterest.com/upload/125960120798214086_Q7SKFTww_222.jpg", "http://media-cache.pinterest.com/upload/211950726183236720_7Kod2qbJ_t.jpg", "http://media-cache.pinterest.com/upload/125045327123930771_LuvhIu65_t.jpg", "http://media-cache.pinterest.com/upload/87186942756265435_zkDGofnk_t.jpg", "http://media-cache.pinterest.com/upload/226165212507107947_FmCa7hLT_t.jpg"], "stats": {"followers_count": 17, "pins_count": 20}, "id": "123778758447498751", "name": "Dawww"}, {"category": "food_drink", "is_collaborator": false, "user_id": "123778827166945150", "description": "", "url": "/cssquirrel/nom-nom-nomophilia/", "is_following": false, "thumbnails": ["http://media-cache.pinterest.com/upload/236931630366384673_cIr5IfF1_222.jpg", "http://media-cache.pinterest.com/upload/280419514268240404_2ysv68TW_t.jpg", "http://media-cache.pinterest.com/upload/192388215301900735_YjfHY9zf_t.jpg", "http://media-cache.pinterest.com/upload/157414949445677782_ETiqDlZ4_t.jpg", "http://media-cache.pinterest.com/upload/284712007662990043_kKnxN3jz_t.jpg"], "stats": {"followers_count": 20, "pins_count": 80}, "id": "123778758447497411", "name": "Nom-nom-nomophilia"}, {"category": "men_apparel", "is_collaborator": false, "user_id": "123778827166945150", "description": "", "url": "/cssquirrel/project-sexypants/", "is_following": false, "thumbnails": ["http://media-cache.pinterest.com/upload/252201647852822759_uwlKOI1e_222.jpg", "http://media-cache.pinterest.com/upload/262264378270304794_88rVBmtm_t.jpg", "http://media-cache.pinterest.com/upload/198439927301238104_ZOX7SIcE_t.jpg", "http://media-cache.pinterest.com/upload/90775748709356579_2Zdk8if8_t.jpg", "http://media-cache.pinterest.com/upload/245657354644409113_GrKBq62Q_t.jpg"], "stats": {"followers_count": 20, "pins_count": 33}, "id": "123778758447497410", "name": "Project Sexypants"}, {"category": "cars_motorcycles", "is_collaborator": false, "user_id": "123778827166945150", "description": "", "url": "/cssquirrel/cars-to-overcompensate-with/", "is_following": false, "thumbnails": ["http://media-cache.pinterest.com/upload/216946907019857635_qiGKPgTa_222.jpg", "http://media-cache.pinterest.com/upload/30258628716631205_PAfHj9Ds_t.jpg", "http://media-cache.pinterest.com/upload/285486063848979846_cZABTXYA_t.jpg", "http://media-cache.pinterest.com/upload/193936327673799615_3wdGZJ7U_t.jpg", "http://media-cache.pinterest.com/upload/253749760224841585_f5N7CY4h_t.jpg"], "stats": {"followers_count": 20, "pins_count": 44}, "id": "123778758447497409", "name": "Cars To Overcompensate With"}, {"category": "geek", "is_collaborator": false, "user_id": "123778827166945150", "description": "", "url": "/cssquirrel/geeeeeek/", "is_following": false, "thumbnails": ["http://media-cache.pinterest.com/upload/123778689728702748_OuOah7Ki_222.jpg", "http://media-cache.pinterest.com/upload/123778689728702742_2MXhVgEb_t.jpg", "http://media-cache.pinterest.com/upload/152418768608872302_FTHuHi9M_t.jpg", "http://media-cache.pinterest.com/upload/160792649165450534_EAB8aKAI_t.jpg", "http://media-cache.pinterest.com/upload/169307267210994707_D0Ht2JrH_t.jpg"], "stats": {"followers_count": 20, "pins_count": 48}, "id": "123778758447497408", "name": "Geeeeeek"}, {"category": "food_drink", "is_collaborator": false, "user_id": "123778827166945150", "description": "", "url": "/cssquirrel/brew/", "is_following": false, "thumbnails": ["http://media-cache.pinterest.com/upload/135389532518003791_9awFAkAM_222.jpg", "http://media-cache.pinterest.com/upload/87116574011433685_49ZFZZUy_t.jpg", "http://media-cache.pinterest.com/upload/44050902575271742_HOZYAXOW_t.jpg", "http://media-cache.pinterest.com/upload/219620919298640329_yQlav4EP_t.jpg", "http://media-cache.pinterest.com/upload/123778689728668385_W9OfOjAj_t.jpg"], "stats": {"followers_count": 20, "pins_count": 34}, "id": "123778758447497407", "name": "Brew"}]}
尽管出现“无效标签”错误,我有什么方法可以处理这个 JSON 对象吗?(不更改我无权访问的服务器端代码)。显然我想要的数据正在被发送,它只是缺少 JSONP 通常期望的函数包装器。