Javascript哈希(node.js)

0xS*_*ina 1 javascript arrays hash node.js

我在访问哈希中的密钥时遇到问题(如果重要的话,我在Node.js中编程).

返回状态和回复时我有一个回调:

client.metadata(folder, options, function(status, reply){
  //console.log(reply)
  console.log(reply)
  console.log("New hash: " + reply['hash']);
});
Run Code Online (Sandbox Code Playgroud)

问题是,reply ['hash']返回undefined.甚至reply.hash是未定义的.如何在回复中访问哈希键?

我记录了回复,它是:

{
  "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"
}
Run Code Online (Sandbox Code Playgroud)

但是当我像上面的例子那样访问哈希回复时,它是:

新哈希:未定义

Sor*_*ren 5

答案可能是字符串类型,您需要将其从JSON转换为JSON.parse(reply)...

查看回复的类型console.log(typeof reply)并查看其内容