离子2:无法显示JSON响应眼帘

问题描述:

我想显示一个JSON响应,但似乎无法显示任何内容:离子2:无法显示JSON响应眼帘

响应:

enter image description here

woo.service。 TS:

getProducts() : Observable<any> { 
    let headers = new Headers(); 
    headers.append('Content-Type', 'application/x-www-form-urlencoded'); 
    return this._http.get(this._url+'products?'+'consumer_key='+this._ck+'&consumer_secret='+this._cs, { 
     headers : headers 
    }).map(res => res.json().items); 
} 

woo.ts:

ngOnInit() { 
     this._wooService.getProducts() 
     .subscribe(
      response => this.response = response, 
      error => console.log(error)); 
      this.isLoading = false; 
    } 

最后的woo.html:

<ion-card-header class="cardHead" text-center> 
    <h2 class="cardHeaderText">{{obj.products.title}}</h2> 

     <p>Prix: {{obj.price_html}}</p> 
</ion-card-header> 

<ion-card-content> 
    <img src="{{obj.images.src}}"> 
    <p class="cardBodyText">{{obj.description}}</p> 
    <p>Tags: {{obj.tags}}</p> 
    <p>Catégories: {{obj.categories}}</p> 
</ion-card-content> 

任何人有一个想法,为什么我不能用* ngFor = “响应#OBJ” 访问?

我认为你的问题是在这里:的

​​

代替:

return this._http.get(this._url+'products?'+'consumer_key='+this._ck+'&consumer_secret='+this._cs, { 
    headers : headers 
}).map(res => res.json().items); 

根据您的响应有效载荷。

小记:您无需为您的获取请求设置Content-Type标题。