Javascript 对象访问;输出正常,选择不起作用
Javascript Object access; Outputs fine, selection not working
所以我有这个对象,当我 console.log 它并在检查器中查看它时,它看起来很好。
Object in Inspector
但是当我打印出对象的键时,我只得到这样的结果:
Object Keys in Inspector
之后我打印的所有内容 (object.value) 看起来像这样:
ƒ (){return f&&(c&&!b&&(h=f.length-1,g.push(c)),function d(b){r.each(b,function(b,c){r.isFunction(c)?a.unique&&j.has(c)||f.push(c):c&&c.length&&"string"!==r.type(c)&&d(c)})}(arguments),c&&!b&&i()),this}
如何才能只访问第一个屏幕截图中的 "responseJSON"?
一些可能很重要的背景信息:
我从 spotify web-api、授权等获得了对象,一切正常。
function getUserData(accessToken) {
return $.ajax({
url: 'https://api.spotify.com/v1/me/player/currently-playing',
headers: {
'Authorization': 'Bearer ' + accessToken
}
});
}
这是因为您正在枚举一个 jQuery 延迟对象属性。延迟对象是异步的,在您的情况下来自 HTTP 请求。
要正确枚举您的对象,您应该首先使用 Deferred.then
等待它可用。替换您的代码:
console.log(Object.keys(your_object))
至:
your_object.then(function(result) {
console.log(Object.keys(result))
}).catch(function(err) {
console.error(err)
})
所以我有这个对象,当我 console.log 它并在检查器中查看它时,它看起来很好。 Object in Inspector
但是当我打印出对象的键时,我只得到这样的结果: Object Keys in Inspector
之后我打印的所有内容 (object.value) 看起来像这样:
ƒ (){return f&&(c&&!b&&(h=f.length-1,g.push(c)),function d(b){r.each(b,function(b,c){r.isFunction(c)?a.unique&&j.has(c)||f.push(c):c&&c.length&&"string"!==r.type(c)&&d(c)})}(arguments),c&&!b&&i()),this}
如何才能只访问第一个屏幕截图中的 "responseJSON"?
一些可能很重要的背景信息: 我从 spotify web-api、授权等获得了对象,一切正常。
function getUserData(accessToken) {
return $.ajax({
url: 'https://api.spotify.com/v1/me/player/currently-playing',
headers: {
'Authorization': 'Bearer ' + accessToken
}
});
}
这是因为您正在枚举一个 jQuery 延迟对象属性。延迟对象是异步的,在您的情况下来自 HTTP 请求。
要正确枚举您的对象,您应该首先使用 Deferred.then
等待它可用。替换您的代码:
console.log(Object.keys(your_object))
至:
your_object.then(function(result) {
console.log(Object.keys(result))
}).catch(function(err) {
console.error(err)
})