1

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

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks that was it. it was a string. After parsing it, it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.