Skip to Content
JSON示例

示例

YouTube JSON API

以下是 YouTube JSON API 响应对象的示例。你可以在这里了解更多关于 YouTube JSON API 的信息:https://code.google.com/apis/youtube/2.0/developers_guide_jsonc.html 

{ "apiVersion": "2.0", "data": { "updated": "2010-02-04T19:29:54.001Z", "totalItems": 6741, "startIndex": 1, "itemsPerPage": 1, "items": [ { "id": "BGODurRfVv4", "uploaded": "2009-11-17T20:10:06.000Z", "updated": "2010-02-04T06:25:57.000Z", "uploader": "docchat", "category": "Animals", "title": "From service dog to SURFice dog", "description": "Surf dog Ricochets inspirational video ...", "tags": [ "Surf dog", "dog surfing", "dog", "golden retriever", ], "thumbnail": { "default": "https://i.ytimg.com/vi/BGODurRfVv4/default.jpg", "hqDefault": "https://i.ytimg.com/vi/BGODurRfVv4/hqdefault.jpg" }, "player": { "default": "https://www.youtube.com/watch?v=BGODurRfVv4&feature=youtube_gdata", "mobile": "https://m.youtube.com/details?v=BGODurRfVv4" }, "content": { "1": "rtsp://v5.cache6.c.youtube.com/CiILENy73wIaGQn-Vl-0uoNjBBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", "5": "https://www.youtube.com/v/BGODurRfVv4?f=videos&app=youtube_gdata", "6": "rtsp://v7.cache7.c.youtube.com/CiILENy73wIaGQn-Vl-0uoNjBBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp" }, "duration": 315, "rating": 4.96, "ratingCount": 2043, "viewCount": 1781691, "favoriteCount": 3363, "commentCount": 1007, "commentsAllowed": true } ] } }

分页示例

此示例演示了 Google 搜索项目如何表示为 JSON 对象,特别关注分页变量。

此示例仅用于说明目的。以下 API 实际上并不存在。 以下是 Google 搜索结果页面示例: 以下是此页面的 JSON 表示示例:

{ "apiVersion": "2.1", "id": "1", "data": { "query": "chicago style pizza", "time": "0.1", "currentItemCount": 10, "itemsPerPage": 10, "startIndex": 11, "totalItems": 2700000, "nextLink": "https://www.google.com/search?hl=en&q=chicago+style+pizza&start=20&sa=N", "previousLink": "https://www.google.com/search?hl=en&q=chicago+style+pizza&start=0&sa=N", "pagingLinkTemplate": "https://www.google.com/search/hl=en&q=chicago+style+pizza&start={index}&sa=N", "items": [ { "title": "Pizz'a Chicago Home Page" // 更多搜索结果字段 } // 更多搜索结果 ] } }

以下是截图中每个彩色框的对应表示(背景颜色对应上面图片中的颜色):

  • 结果 11 - 20,共约 2,700,000 = startIndex
  • 结果 11 - 20,共约 2,700,000 = startIndex + currentItemCount - 1
  • 结果 11 - 20,共约 2,700,000 = totalItems
  • 搜索结果 = items(适当格式化)
  • 上一页/下一页 = previousLink / nextLink
  • “Gooooooooooogle” 中的编号链接 = 从 pageLinkTemplate 派生。开发者负责计算 {index} 的值并将这些值替换到 pageLinkTemplate 中。pageLinkTemplate{index} 变量计算如下:
    • 索引 #1 = 0 * itemsPerPage = 0
    • 索引 #2 = 2 * itemsPerPage = 10
    • 索引 #3 = 3 * itemsPerPage = 20
    • 索引 #N = N * itemsPerPage
Last updated on