Ionic 2访问JSON元素

时间:2017-06-28 04:04:11

标签: json angular ionic2

我有这个功能

downlaod(){
        console.log('ab')
        this.JobsServiceProvider.getResume().then(result=>{ 

        })
    }

返回此json

  

{"履历" {" owner_id":131461,"文件名":" cvabdulmuizzabdulhalimislamicstudies.doc""位置& #34;:" asset.jobstore.com/uploads/document/131461","状态":1," owner_type":"求职者&#34 ;," ID":2330482," createdAt":" 2017-06-22T08:11:56.000Z"" updatedAt":& #34; 2017-06-22T08:11:56.000Z"}}

我如何访问它,我尝试了result.resume,result.owner_id。它不起作用

1 个答案:

答案 0 :(得分:2)

您的服务应以json格式返回响应。

this.http.get(url)
               .toPromise()
           .then(response => response.json())
           .catch(this.handleError);

在您的组件中,您需要访问json

downlaod(){
        console.log('ab')
        this.JobsServiceProvider.getResume().then(result=>{
         console.log(result);
// access result 
          result.owner_id
        })
    }

你可以做console.log(结果)来检查你是否正在接收json