我正在尝试从Google自定义搜索json api获取数据以用于我的扩展程序。但是,每当我尝试在下面发送获取请求时,都会引发一个我不知道如何解决的错误。
SyntaxError:JSON输入意外结束
我尝试在浏览器中执行相同的请求,但似乎工作正常。
我尝试使用XMLHttp请求来代替,这也没有用。我还尝试使用访存api从其他有效的api获取数据。我还尝试更改权限,并在manifest.json的权限中添加了https://www.googleapis.com/customsearch/v1。
fetch('https://www.googleapis.com/customsearch/v1?q=skeet&cx=mysearchid&key=my_api_key')
.then(function(response) {
return response.json();
})
.then(function(myJson) {
console.log(JSON.stringify(myJson));
});