Javascript散列(node.js)

我有一个哈希访问键(我在Node.js编程,如果重要的话)的麻烦。

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

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

问题是,reply ['hash']返回undefined。 即使reply.hash是未定义的。 我怎样才能访问散列键回复?

我logging回复,它是:

 { "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" } 

但是当我像上面的例子那样访问hash时,它是:

新的哈希:未定义

答案可能是stringtypes,您需要将其从JSON转换为JSON.parse(reply)

console.log(typeof reply)检查回复的types,看看它是什么意思