我是刚来的,需要你的帮助。我有一个角度服务,它具有如下所示的api调用函数。

    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).

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

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.node.js - 在Angular中,如何解析和提取具有复杂结构(JSON)的HTTP响应?-LMLPHP

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/

10-12 07:34
查看更多