因为我今天不能上班(阑尾切除术后),但仍然想学习我的PowerShell技能,我决定尝试访问魔兽世界API并拉下拍卖行数据以获取乐趣。
$apiKey = "myapikey"
$serverName = "MyServer"
$webAddress = "https://us.api.battle.net/wow/auction/data/"
$url = $webAddress + $serverName + "?apikey=" + $apiKey
$response = Invoke-RestMethod -Uri $url -ContentType "application/json"
$aucURL = $response.files.url
$aucTime = $response.files.lastModified
$response = Invoke-RestMethod -Uri $aucURL
$aucData = $response.auctions #Always returns blank
我到达这一点,得到一个巨大的数据列表,看起来像下面,我的生活似乎无法访问拍卖数据。
{
"realms": [
{"name":"MyServer","slug":"MyServer"}],
"auctions": [
{"auc":723774847,"item":109167,"owner":"Laddypally","bid":369550,"buyout":389000,"quantity":1,"timeLeft":"VERY_LONG","rand":0,"seed":0,"context":1},
{"auc":724234542,"item":2996,"owner":"Mazramtaim","bid":760000,"buyout":800000,"quantity":20,"timeLeft":"VERY_LONG","rand":0,"seed":0,"context":0},
{"auc":723207271,"item":133563,"owner":"Alsalak","bid":1187500,"buyout":1250000,"quantity":5,"timeLeft":"LONG","rand":0,"seed":0,"context":0}]}
我获取$responses的方法。在我过去的工作中,任何与PS相关的东西都是有效的,但在这里不是。有什么原因吗?
升级到PowerShell 5修复了这个问题。我没有改变任何代码,所以问题一定是PS4如何处理大型JSON请求。