【问题标题】:Ionic 2 accessing JSON elementsIonic 2 访问 JSON 元素
【发布时间】:2017-06-28 04:04:10
【问题描述】:

我有这个功能

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

        })
    }

返回这个 json

{"resume":{"owner_id":131461,"filename":"cvabdulmuizzabdulhalimislamicstudies.doc","location":"asset.jobstore.com/uploads/document/131461","status":1," owner_type":"jobseeker","id":2330482,"createdAt":"2017-06-22T08:11:56.000Z","updatedAt":"2017-06-22T08:11:56.000Z"}}

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

【问题讨论】:

    标签: json angular ionic2


    【解决方案1】:

    您的服务应该以 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(result)来检查你是否收到json

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-14
      • 1970-01-01
      • 2016-11-01
      • 2017-08-12
      • 2012-09-09
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      相关资源
      最近更新 更多