2013-06-03 5 views
1

Google 도서 API에서 도서 목록을 가져 왔습니다. localStorage에 JSON 객체를 저장 한 다음 객체에 다시 파싱했습니다. var books = JSON.parse(localStorage.books);jQuery를 사용하여 Google 도서 JSON 개체 검색

이제 특정 책 항목에 대한 정보를 가져 오기 위해 책 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" 
    }, 
+0

@JeffS 왜 당신은 내가 아니라 내 질문에 게시 한 링크를-게시 다시입니까? –

답변

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

https://developers.google.com/books/docs/v1/reference/volumes/list - 참고로 도서에 대한 json 반환 방법을 보여주는 Google 도서 API 문서가 더 적합 할 것입니다. – sh0ber

+0

JSON이나 데이터 구조에별로 좋지 않습니다. 도서에 대한 나머지 정보와 관련된 도서의 ID입니까? –

+0

예. 이 함수는 이것을 보여준다. 표시된대로 ID를 전달하면 해당 ID와 연관된 전체 책 객체를 반환합니다. 예제에서는 ID 'HGsoQKfXs90C'를 검색하고 일치하는 책을 변수'book'에 저장합니다. 'etag' 속성을 참조 할 수 있습니다 : 예 :'book.etag' – sh0ber