Convert «System.Collections.ArrayList» ?

Welcome Forums General PowerShell Q&A Convert «System.Collections.ArrayList» ?

Viewing 2 reply threads
  • Author
    Posts
    • #258677
      Participant
      Topics: 1
      Replies: 2
      Points: 12
      Rank: Member

      Hy,

      I’m discovering Powershell, I would like to use value from a JSON file but no way to convert them into Real or float or int…

      So I can’t use them.

      I’m noob please help

      This  is my try :

      Thx.

      • This topic was modified 1 month ago by grokkit. Reason: code formatting
    • #258719
      Participant
      Topics: 16
      Replies: 1794
      Points: 3,300
      Helping Hand
      Rank: Community Hero

      There are many ways to do perform casts. When you get data from the API, it’s a string. Powershell will guess and try to do conversions before math operations, but you can also force the casting with types. Using Invoke-RestMethod will automatically convert from JSON to a PSObject. Once you’ve done that, you can use Select object to do conversions and even add a property with the completed math.

      Output:

    • #258758
      Participant
      Topics: 1
      Replies: 2
      Points: 12
      Rank: Member

      Thank you for answer.

      I’m sorry but I don’t understand how to use your code.

      I would like to store the result of of (reward) X (price) for coin:ETH

      I try this but no success (no output) :

      $base_url = "https://api.minerstat.com/v2/coins?list=BTC,ETH,ETC"
      $WebRequest = Invoke-RestMethod $base_url -Method GET

      $ETH_price = $WebRequest | where{$_.coin -eq "ETH"} | Select-Object -Property @{Name='price';Expression={[float]$_.price}}

      $ETH_reward = $WebRequest | where{$_.coin -eq "ETH"} | Select-Object -Property @{Name='reward';Expression={[float]$_.reward}}

      $ETH_proffit = ($ETH_price) * ($ETH_reward)
      $ETH_proffit

       

      Thx.

      • This reply was modified 1 month ago by rogains20.
Viewing 2 reply threads
  • You must be logged in to reply to this topic.