如何解决在powershell中转换json时如何解决“无法绑定参数'uri'无法转换......”?
我在 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"
非常感谢您的帮助,谢谢!
解决方法
ConvertFrom-Json cmdlet 的输入是一个 JSON 对象。查看下面的文档了解更多信息
$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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。