字符串来自Google Books API json的所有标题

时间:2014-03-26 14:41:21

标签: json string google-books

我希望从Google图书馆的书架中获取所有标题,并生成一系列以逗号分隔的标题。这是我的尝试:

var allTitles = [];

$.getJSON("https://www.googleapis.com/books/v1/users/115939388709512616120/bookshelves/1004/volumes?key=MYAPIKEY",function(data){

     $.each(data.items, function (i, item) {

         allTitles.push(data.items[0].volumeInfo.title);

  });

var newTitleString = allTitles.join(', ');
    alert(newTitleString);   

http://jsfiddle.net/nathanbweb/YzXLW/

我如何使这项工作?

1 个答案:

答案 0 :(得分:0)

好的,我能够从this回答中找出答案。这是有效的:

$.getJSON("https://www.googleapis.com/books/v1/users/115939388709512616120/bookshelves/1004/volumes?key=MYAPIKEY",function(data){

    var titles = [];

    data.items.forEach(function(e,i){titles.push(e.volumeInfo.title);});
         console.log(titles);

     var newTitleString = titles.join(', ');
         console.log(newTitleString);        

  });

http://jsfiddle.net/nathanbweb/YzXLW/3/