无法访问请求承诺响应中的值

我有下面的代码,它给了我响应,但是当我尝试访问响应的属性时,我变得“未定义”

const request = require('request-promise');

const option= {
method: 'GET',
uri: 'urihere',
qs: {
    q: 'Mark'
},
json: true,
resolveWithFullResponse: true,
headers: {
    'User-Agent': 'requestXYZPromise',
    'Authorization': ''
}
}

request(option)
    .then(response => {

})
.catch(error => {
})

怎么了请提出建议。

更新-响应数据。我试图获得“分数”

{
"responseHeader":{
"ist":"json",
"version":"1.0"}},
"response":{"score":2,"start":0,"maxScore":18.9204}
}
评论
  • uqui
    uqui 回复

    Your response has itself a property called response. To access your score value you would need to call response.response.score.

  • 看!灰鸡
    看!灰鸡 回复
    {
      "response": {
        "score": 2,
        "start": 0,
        "maxScore": 18.9204
      }
    }
    

    这是您的回复,您可以按以下方式访问。

    request(option)
        .then(response => {
          console.log(response.response.score)
    })
    .catch(error => {
    })