我如何取消一个exception的JSONvariables?
我试图做一个Node.js机器人,所以我find了一个模块,安装它,并试用其示例代码。 现在,我有一个asynchronous函数,从API加载一些文本。 这是代码:
(async () => { // Display user's balance balance = kraken.api('Balance'); console.log(await balance); })();
当我运行上面的代码时,这是我在commandprompt中得到的:
{ error: [], result: { A: '2.0', BC: '0.005', BCA: '111' } }
我怎样才能使它只logging这个看起来像一个数组的特定部分? 我试过做类似的东西(让它返回2.0):
console.log(await balance.result.A)
但是,这似乎不工作,因为它返回这个:
(node:6604) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'A' of undefined (node:6604) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
出于想法和需要帮助..谢谢!
你要把你的等待声明放在括号里,就像这样:
console.log((await balance).result.A);
这将asynchronous获取余额,然后logging结果属性。