1

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

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

现在,我想根据图书 ID 提取该特定图书条目的信息。我已经设法找到一本书的 ID,将它们显示在一个列表中,但是一本书的 ID 和关于该书的其余信息是否有任何关联?如果是,您将如何从其 id 中获取特定书籍的所有数据?

JSON 示例完整的 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"
  },
4

1 回答 1

1
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');
于 2013-06-03T20:04:30.330 回答