Javascript 我正在接收一个对象作为响应,我使用response.JSON()将其转换为JSON,但无法从JSON中获取值?
我正在向spotify发送一个请求,从他们那里获取一个id值,以便稍后在post请求中使用Javascript 我正在接收一个对象作为响应,我使用response.JSON()将其转换为JSON,但无法从JSON中获取值?,javascript,json,Javascript,Json,我正在向spotify发送一个请求,从他们那里获取一个id值,以便稍后在post请求中使用 fetch('https://api.spotify.com/v1/me', { headers: { 'Authorization': `Bearer ${token}` } }).then(response => { let jsonResponse = response.json(); }); 当使用response.json()转换为jason时,此
fetch('https://api.spotify.com/v1/me', {
headers: {
'Authorization': `Bearer ${token}`
}
}).then(response => {
let jsonResponse = response.json();
});
当使用response.json()转换为jason时,此代码返回一个如下所示的对象
Promise{}\uuuuu proto\uuuuu:PromiseStatus[[PromiseStatus]]:“已解决”[[PromiseValue]]:Objectdisplay\u name:“Jesse James”外部\u URL:{spotify:https://open.spotify.com/user/1257754444}追随者:{href:null,总数:3}href:https://api.spotify.com/v1/users/1257754444id:“1257754444”图像:[{…}]类型:“用户”uri:“spotify:用户:1257754444”__原型:对象
现在我想提取id值。但是当我使用
log(jsonResonse.id)我得到一个未定义的。如何获取该值?response.json()
返回承诺
因此,只需按如下方式继续承诺链
fetch('https://api.spotify.com/v1/me', {
headers: {
'Authorization': `Bearer ${token}`
}
})
.then(response => response.json()) // response.json() returns a Promise
.then(jsonResponse => {
// here jsonResponse is the json you were looking for
});
response.json()
返回承诺
因此,只需按如下方式继续承诺链
fetch('https://api.spotify.com/v1/me', {
headers: {
'Authorization': `Bearer ${token}`
}
})
.then(response => response.json()) // response.json() returns a Promise
.then(jsonResponse => {
// here jsonResponse is the json you were looking for
});
您能给我看一下原始响应吗?
jsonResponse
是json响应的承诺您能给我看一下原始响应吗?jsonResponse
是json响应的承诺