简体   繁体   English

使用从 Invoke-RestMethod 返回的值

[英]Work with value returned from Invoke-RestMethod

I am very new to powershell and I don't know what to do.我对 powershell 很陌生,我不知道该怎么做。 I have the following code我有以下代码

$rest = Invoke-RestMethod -Uri https://blockchain.info/balance?active=3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP

$rest outputs: $rest 输出:

$rest

3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP                                 
----------------------------------                                 
@{final_balance=150050010291; n_tx=20; total_received=150050010291}

How can i load the value of final_balance into a variable?如何将 final_balance 的值加载到变量中?

Because of the fact that 3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP starts with a digit, you get an error when trying to access that property with the syntax $rest.3P... .由于3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP以数字开头,因此在尝试使用$rest.3P...语法访问该属性时会出现错误。 What you can do instead, is wrapping it in a string like: $rest."3P.." .您可以做的是将其包装在一个字符串中,例如: $rest."3P.." See the below results:请参阅以下结果:

> $rest = Invoke-RestMethod -Uri https://blockchain.info/balance?active=3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP

3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP
----------------------------------
@{final_balance=150050010291; n_tx=20; total_received=150050010291}

> $rest.3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP

ParserError:
Line |
   1 |  $rest.3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP
     |        ~
     | Missing property name after reference operator.

> $rest."3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP"

final_balance n_tx total_received
------------- ---- --------------
 150050010291   20   150050010291

> $final_balance = $rest."3PyoQHou1BQeJnbkpKpgQNxF8wk3EXXVHP".final_balance
> $final_balance

150050010291

In the terminal, you can press Ctrl+Space to get some autocomplete.在终端中,您可以按 Ctrl+Space 来获得一些自动完成功能。 Maybe this depends on the terminal, but if it works, it is really helpful for navigating into properties and getting recommendations.也许这取决于终端,但如果它有效,它对于导航到属性和获取建议非常有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM