【问题标题】:How do I fix a "cannot bind parameter 'uri'. Cannot convert the...." when converting json in powershell?在powershell中转换json时,如何解决“无法绑定参数'uri'。无法转换......”?
【发布时间】:2021-06-13 01:19:40
【问题描述】:

我在 powershell 中做一个 Get-Weather 项目,我从 weatherapi.com 中提取数据。我能够使用 API 密钥成功连接到网站,但是当我尝试从脚本中的 json 转换它时,它不起作用。我得到的错误是:

“无法绑定参数'Uri'。无法转换...” 我尝试了很多不同的方法来写这个:

$response = Invoke-RestMethod -uri $url -Method Get -ResponseHeadersVariable r -StatusCodeVariable s

$weatherobject = ConvertFrom-Json $url

对网站的请求是:

$url = Invoke-WebRequest "http://api.weatherapi.com/v1/forecast.json?key=$key&q=$location&days=$Days"

非常感谢您的帮助,谢谢!

【问题讨论】:

    标签: json powershell api weather-api


    【解决方案1】:

    ConvertFrom-Json cmdlet 的输入是一个 JSON 对象。查看下面的文档了解更多信息

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertfrom-json?view=powershell-7.1#description

    $url = "http://api.weatherapi.com/v1/forecast.json?key=$key&q=$location&days=$Days"
    $response = Invoke-RestMethod -uri $url -Method Get -ResponseHeadersVariable r -StatusCodeVariable s
    $weatherobject = ConvertFrom-Json $response
    

    【讨论】:

      猜你喜欢
      • 2017-11-30
      • 2019-05-07
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 2022-01-18
      • 2020-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多