小编Oce*_*vez的帖子

“响应”类型的参数不能分配给“字符串”类型的参数

我正在做这个项目。这个想法是从谷歌图书 API 检索书籍,使用 angular 4

我正在努力理解如何阅读 JSON 响应,我仍在学习 Angular。我在互联网上搜索并在 GitHub google bookstore上找到了这个源代码

我收到以下错误

Argument of type 'Response' is not assignable to parameter of type 'string'.
Run Code Online (Sandbox Code Playgroud)

对于这条线

  let bookResponse = JSON.parse(body);
Run Code Online (Sandbox Code Playgroud)

我不确定我是否以正确的方式做这件事。感谢你的帮助

下面是我发送 HTTP 请求的方法。

  getBooks(searchparam: any){
let par = new HttpParams();
par.set('q', searchparam);

return this.httpClient.get('https://www.googleapis.com/books/v1/volumes', {
  params : new HttpParams().set('q',searchparam)
}).map(
  (response: Response) => {
    let data = response;

    return data;
  }
);
Run Code Online (Sandbox Code Playgroud)

}

下面是从 HTTP 请求中获取数据并读取 JSON 响应的方法

  getBook() {

const dataArrya = this.searchForm.get('param').value;

console.log(dataArrya);
this.requestService.getBooks(dataArrya)
  .subscribe(
    response …
Run Code Online (Sandbox Code Playgroud)

json httpclient google-apis-explorer angular

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

angular ×1

google-apis-explorer ×1

httpclient ×1

json ×1