使用jQuery搜索Google Books JSON对象

Searching a Google Books JSON object with jQuery

本文关键字:JSON 对象 Books Google jQuery 搜索 使用      更新时间:2023-09-26

我从Google books API获取了一个图书列表。我将JSON对象保存在localStorage中,然后在对象中再次解析它:

var books = JSON.parse(localStorage.books);

现在我想根据图书Id提取特定图书条目的信息。我已经找到了特定书籍的ID,并将它们显示在列表中,但是书籍的ID和关于该书的其他信息之间是否存在任何关联?如果是,如何从某本书的id中获取它的所有数据?

数据的完整API示例
{
 "kind": "books#volume",
 "id": "HGsoQKfXs90C",
 "etag": "O6jaKOAAZvI",
 "selfLink": "https://www.googleapis.com/books/v1/volumes/HGsoQKfXs90C",
 "volumeInfo": {
  "title": "John D. Rockefeller",
  "subtitle": "Anointed with Oil",
  "authors": [
   "Grant Segall"
  ],
  "publisher": "Oxford University Press",
  "publishedDate": "2001-02-08",
  "description": "Chronicles the life and accomplishments of the philanthropist and industrialist who founded the Standard Oil Company.",
  "industryIdentifiers": [
   {
    "type": "ISBN_10",
    "identifier": "0195121473"
   },
   {
    "type": "ISBN_13",
    "identifier": "9780195121476"
   }
  ],
  "pageCount": 128,
  "dimensions": {
   "height": "25.00 cm",
   "width": "23.10 cm",
   "thickness": "1.50 cm"
  },
function getBook(id){
    for(var i=0;i<books.items.length;i++){
        if(books.items[i].id === id){
            return books.items[i]; 
        }
    }
    return false;
}
var book = getBook('HGsoQKfXs90C');