gpt4 book ai didi

node.js - 在 Angular 中,如何解析和提取具有复杂结构(JSON)的 HTTP 响应?

转载 作者:搜寻专家 更新时间:2023-10-30 21:46:29 29 4
gpt4 key购买 nike

我是 Angular 的新手,需要你的帮助。我有一个具有 API 调用功能的 Angular 服务,如下所示。

    searcheBay() {        console.log("calling ebay service");        return this.httpClient.get (this.ebayURL);      }

and I am calling this function from the component as shown below.

    this.searchService.searcheBay().subscribe((data) => {          this.svcdata  =  data      });

The data variable has complex JSON structure (see the image below).

JSON structure

The data I am looking to read is held by "searchResult" element. Could you suggest how to parse and extract the "searchResult" element? Thanks in advance.

I debugged in the Safari DEV console and see the element accessibility as shown below.DEV console debug

When I updated the same code in my component, I encounter compile: ERROR in src/app/search/search.component.ts(20,29): error TS2339: Property 'findItemsByKeywordsResponse' does not exist on type 'Object'. Please suggest your thoughts.

 serviceOnButtonClick(){
this.searchService.searcheBay().subscribe((data) => {
this.svcdata = data.findItemsByKeywordsResponse[0].searchResult

});

最佳答案

@javapedia.net 试试这个,如果你响应 data 对象与你在图像中显示的相同,

this.searchService.searcheBay().subscribe((data) => {
this.svcdata = data.findItemsByKeywordsResponse[0].searchResult;
console.log(this.svcdata);
});

编辑

this.searchService.searcheBay().subscribe((data: any) => {
this.svcdata = data.findItemsByKeywordsResponse[0].searchResult;
console.log(this.svcdata);
});

关于node.js - 在 Angular 中,如何解析和提取具有复杂结构(JSON)的 HTTP 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54121399/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com