Reputation: 21553
I am having trouble with accessing a key in a hash (I am programming in Node.js if that matters).
I have a callback when return a status and a reply like this:
client.metadata(folder, options, function(status, reply){
//console.log(reply)
console.log(reply)
console.log("New hash: " + reply['hash']);
});
The problem is, reply['hash'] returns undefined. even reply.hash is undefined. How can I access the hash key in reply?
I logged reply and it is:
{
"hash": "e533d2c19d236d0d4f84e2a9666659e1",
"revision": 802,
"rev": "32203a97cb5",
"thumb_exists": false,
"bytes": 0,
"modified": "Wed, 04 Jan 2012 02:39:18 +0000",
"path": "/foo",
"is_dir": true,
"icon": "folder",
"root": "dropbox",
"contents": [],
"size": "0 bytes"
}
but when i access hash in reply like in above example, it's:
New hash: undefined
Upvotes: 1
Views: 392
Reputation: 14688
It could be possible that the reply is a string type, and you need to convert it from JSON with a JSON.parse(reply)
...
Check out the type of the reply with console.log(typeof reply)
and see what it say
Upvotes: 5