Javascript 访问解析的promise对象属性

Javascript 访问解析的promise对象属性,javascript,promise,fetch-api,Javascript,Promise,Fetch Api,访问已解析的promise对象属性时遇到问题 使用fetch时,我有一个 .thenresponse=>console.logresponse.json 我正在尝试通过以下操作访问响应对象的用户属性: .thenresponse=>console.logresponse.json.user 它返回的是未定义的 正确的方法是什么?response.json返回另一个承诺。您需要使用另一个。然后回调: fetch(...) .then(response => response.json()

访问已解析的promise对象属性时遇到问题

使用fetch时,我有一个

.thenresponse=>console.logresponse.json

我正在尝试通过以下操作访问响应对象的用户属性:

.thenresponse=>console.logresponse.json.user

它返回的是未定义的

正确的方法是什么?

response.json返回另一个承诺。您需要使用另一个。然后回调:

fetch(...)
  .then(response => response.json())
  .then(data => console.log(data.user))
json返回另一个承诺。您需要使用另一个。然后回调:

fetch(...)
  .then(response => response.json())
  .then(data => console.log(data.user))