Looks like data.results is an array, so you'll have to loop through it. If you just want the first result, you could get at the book_details array with data.results[0].book_details.
On Wed, Sep 28, 2011 at 3:28 PM, Nate Hill <nathanielh...@gmail.com> wrote: > Anybody out there using the NY times best seller API to do stuff on their > library websites? > I can't figure out what's wrong with my code here. > Data is returned as "null"; I can't seem to parse the response with jQuery. > Any help would be supercool. > I removed the API key - my code doesn't actually contain 'xxxx'. > Here's the jQuery: > > jQuery(document).ready(function(){ > $(function(){ > //json request to new york times > $.getJSON(' > http://api.nytimes.com/svc/books/v2/lists/hardcover-fiction.json?&api-key=xxxx', > > function(data) { > //loop through the results with the following > function > $.each(data.results.book_details, function(i,item){ > //turn the title into a variable > var bookTitle = item.title; > $('#container').append('<p>'+bookTitle+'</p>'); > > }); > }); > }); > }); > > > Here's a snippet of the JSON response: > > { > "status": "OK", > "copyright": "Copyright (c) 2011 The New York Times Company. All Rights > Reserved.", > "num_results": 35, > "last_modified": "2011-09-23T12:00:29-04:00", > "results": [{ > "list_name": "Hardcover Fiction", > "display_name": "Hardcover Fiction", > "updated": "WEEKLY", > "bestsellers_date": "2011-09-17", > "published_date": "2011-10-02", > "rank": 1, > "rank_last_week": 0, > "weeks_on_list": 1, > "asterisk": 0, > "dagger": 0, > "isbns": [{ > "isbn10": "0399157786", > "isbn13": "9780399157783" > }], > "book_details": [{ > "title": "NEW YORK TO DALLAS", > "description": "An escaped child molester pursues Lt. Eve > Dallas; by Nora Roberts, writing pseudonymously.", > "contributor": "by J. D. Robb", > "author": "J D Robb", > "contributor_note": "", > "price": 27.95, > "age_group": "", > "publisher": "Putnam", > "primary_isbn13": "9780399157783", > "primary_isbn10": "0399157786" > }], > "reviews": [{ > "book_review_link": "", > "first_chapter_link": "", > "sunday_review_link": "", > "article_chapter_link": "" > }] > > > -- > Nate Hill > nathanielh...@gmail.com > http://www.natehill.net >