如何在Angular 4中解析Json响应

如何在Angular 4中解析Json响应,angular,ionic3,Angular,Ionic3,嗨,我是爱奥尼亚angular应用程序开发的初学者,使用下面的代码进行Http调用,我得到了json格式的响应,现在我想在列表中显示响应标题,我尝试了很多,但没有得到结果。有人能帮我吗 Api url: home.ts: home.html: {{c.title}} 您使用了错误的键来获取HTML部分中的值,代码应该是- <h2>{{c.data.title}}</h2> 更新 如果您使用的是httpClient,那么就不需要使用json()也可以删除{注意:'re

嗨,我是爱奥尼亚angular应用程序开发的初学者,使用下面的代码进行Http调用,我得到了json格式的响应,现在我想在列表中显示响应标题,我尝试了很多,但没有得到结果。有人能帮我吗

Api url:

home.ts: home.html:

{{c.title}}

您使用了错误的键来获取HTML部分中的值,代码应该是-

<h2>{{c.data.title}}</h2>
更新 如果您使用的是
httpClient
,那么就不需要使用
json()
也可以删除
{注意:'response'}
,因为在您的用例中不需要这样做。

使用rxmap

import 'rxjs/add/operator/map';

this.http.post('https://www.reddit.com/r/gifs/top/.json?limit=2&sort=hot',{ observe:'response'}).map(res => res.json()).subscribe(data => {
   console.log(data.data);
});
试试这个

this.http.get('https://www.reddit.com/r/gifs/top/.json?limit=2&sort=hot',{ observe:'response'}).subscribe( res => { console.log(res) ;          
      this.countries = info['data'].children;
  });

在询问之前,您是否查阅了爱奥尼亚的文档?这是一个post请求,该问题要求一个get请求this.http.get(“”,{observe:'response}).map(res=>res.json()).subscribe(data=>{console.log(data.data);});未找到模块:错误:无法解析'rxjs/add/operator/map'this.countries=res.data&&res.data.children;行给出错误-->数据在HttpResponsey中不存在为了在分配给变量之前对其进行控制台您在api Url?中看到了我的响应,我想在列表中显示标题,但您的回答显示了错误请尝试详细说明您的代码,因为我是begginer@AbhiRam用工作示例检查我的更新答案
<h2>{{c.title}}</h2>
this.http.get('https://www.reddit.com/r/gifs/top/.json?limit=2&sort=hot', {observe:'response'}).subscribe( res => { 
      console.log(res) ;
      let response = res.body;
      this.countries = response.data.children;
    });
import 'rxjs/add/operator/map';

this.http.post('https://www.reddit.com/r/gifs/top/.json?limit=2&sort=hot',{ observe:'response'}).map(res => res.json()).subscribe(data => {
   console.log(data.data);
});
this.http.get('https://www.reddit.com/r/gifs/top/.json?limit=2&sort=hot',{ observe:'response'}).subscribe( res => { console.log(res) ;          
      this.countries = info['data'].children;
  });