使用jQuery搜索Google Books JSON对象

时间:2013-06-03 19:45:06

标签: jquery ajax json api object

我从Google Books API获取了一个图书清单。我已经在localStorage中保存了JSON对象,然后我再次在对象var books = JSON.parse(localStorage.books);

中进行了解析

现在我希望根据书籍Id,为特定的书籍条目提取信息。我已经设法找到了如何查找特定书籍的ID,在列表中显示它们,机器人是否有任何关于书籍ID的关联,以及有关该书籍的其他信息。如果你是如何从它的id获取特定书籍的所有数据。

JSON示例Full API example of data

{
 "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"
  },

1 个答案:

答案 0 :(得分: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');