PowerShell函数返回带有Extra' Counter'的数组。值
#inside函数ArrayList有51个项目,但是该函数返回102个项目ArrayList #0到#51是INT值0到51,#51至#101是预期的JSON对象吗?
function Get-RedditTopics () {
$arrayList = New-Object -TypeName "System.Collections.ArrayList"
$url = 'https://www.reddit.com/r/worldnews/.json'
$pages = 2
$after = ""
for ($i = 0; $i -lt $pages; $i++) {
if ($i -gt 0) {
$url = $url + "?after=$after"
}
$result = Invoke-RestMethod $url
foreach ($item in $result.data.children) {
$arrayList.Add($item.data)
}
$after = $result.data.after
}
return $arrayList #51 items, ok!
}
$redditTopics = Get-RedditTopics #function returns $arrayList with 102 items
write-host "redditTopics count: $($redditTopics.Count)"
#Inside the function the arrayList has 51 items, but the function returns a 102 items arrayList
#0 to #51 are int values 0 to 51, #51 to #101 are the expected json objects?
function Get-RedditTopics () {
$arrayList = New-Object -TypeName "System.Collections.ArrayList"
$url = 'https://www.reddit.com/r/worldnews/.json'
$pages = 2
$after = ""
for ($i = 0; $i -lt $pages; $i++) {
if ($i -gt 0) {
$url = $url + "?after=$after"
}
$result = Invoke-RestMethod $url
foreach ($item in $result.data.children) {
$arrayList.Add($item.data)
}
$after = $result.data.after
}
return $arrayList #51 items, ok!
}
$redditTopics = Get-RedditTopics #function returns $arrayList with 102 items
write-host "redditTopics count: $($redditTopics.Count)"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论