google books api getJSON返回语法错误

时间:2013-11-21 13:32:47

标签: jquery json google-api syntax-error

我有以下问题,我现在正在工作几天。 我想从Google Books API发出json请求。

使用Firefox的Firebug开发人员工具,控制台显示“SyntaxError:missing; before statement”并向我显示返回的文本: {“number_of_results”*:* 63,“search_results “:[{”page_id“:”PA33“,等等。

似乎返回的json无效(我检查了它,它是有效)。但是在网络选项卡中,Firefox从GET语句中获取(或创建?)一个json对象,以便在JSON选项卡中进行检查。即使google-server返回JSON并且我期待JSONP,为什么我可以在Firebug中检查JSON对象?

如果Firefox向我展示json-object,为什么我会收到此错误并且无法在运行时自行创建json-object?提前谢谢!

function searchInBook(){

    var newUrl = 'https://www.googleapis.com/books/v1/volumes?q=isbn:0738531367&someting&callback=?';
    $.ajax({
        url: newUrl,
        dataType: 'jsonp',
        success: function(data){
            bookId = data.items[0].id;
            console.log("received book-id:" + bookId);
            bookUrl = "http://books.google.de/books?id="+bookId+"&printsec=frontcover&hl=de&jscmd=SearchWithinVolume&q="+searchquery+"&scoring=r#v=onepage&q&f=false&myCallback=?";
            console.log(bookUrl);

            $.ajax({
                url: bookUrl,
                dataType: 'jsonp',
                success: function(bookData){
                    $("#json-result").html(JSON.stringify(bookData));
                    console.log(JSON.stringify(bookData));
                },
                error: function( foo ) {
                  console.log( "ERROR:  " + foo );
                }
            });
        },
        error: function( foo ) {
          alert( "ERROR:  " + foo );
        }
    });     

}

0 个答案:

没有答案