0

因为我今天不能上班(阑尾切除术后),但仍想提高我的 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.whatever 的方法在过去与我的工作相关的 PS 东西一起工作,但在这里没有。有什么理由吗?

4

1 回答 1

0

升级到 PowerShell 5 解决了这个问题。我没有更改任何代码,所以问题一定在于 PS4 如何处理大型 JSON 请求。

于 2016-09-06T14:48:21.690 回答