Lali Pali
Lali Pali

Reputation: 627

Searching a Google Books JSON object with jQuery

I have fetched a list of books from Google Books API. I have saved the JSON object in localStorage, and then I have parsed it again in an object:

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

Now I want, based on book Id, to pull information for that particular book entry. I have managed to find the IDs for a specific book, showing them in a list, but is there any association of the ID of a book, and the rest of the information about that book? And if yes, how would you fetch all the data for a particular book from its id?

A JSON sample 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"
  },

Upvotes: 1

Views: 970

Answers (1)

Dan
Dan

Reputation: 63059

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');

Upvotes: 1

Related Questions