从dev.battle.net解析带有Powershell的JSON(魔兽世界API)

时间:2016-09-02 19:06:08

标签: api powershell world-of-warcraft

因为我今天无法上班(阑尾切除术后),但仍想继续使用我的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}]}

我采取$ response的方法。过去我的工作与我的工作有关,但不在这里。有什么理由吗?

1 个答案:

答案 0 :(得分:0)

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