杰森& Powershell查询选择

时间:2018-01-26 10:07:13

标签: json powershell

我有JSON数据,我想用Powershell处理。我可以选择单独的节点并使用它,但我不知道如何加入多个节点(如果是目标,我有id_goal,其中包含来自名单(Team1或Team2)的玩家名称ID。一看,帮助我?

我能够以Out-Gridview作为目标列表,并通过-PassTrough,我可以使用所选数据。但我缺少球员姓名(我只是拉他的身份证)。你会如何加入这个“表”? 这是JSON数据: http://textuploader.com/dmwbf

这是半工作代码:

$MatchInfo = Invoke-WebRequest $request | ConvertFrom-Json

$Competition_id = $MatchInfo.competition.id_competition

$Goals=$MatchInfo.goals
$RosterA=$MatchInfo.team1
$RosterB=$MatchInfo.team2

$GoalsTable = @()
$A=0
$B=0
foreach ($record in $Goals)
{
$GoalsRecord = @{}
$GoalsRecord.id_goal=$record.id_goal
$GoalsRecord.id_match=$record.id_match
$GoalsRecord.id_team=$record.id_team
$GoalsRecord.time=$record.time
$GoalsRecord.goal=$record.goal
$GoalsRecord.assist1=$record.assist1
$GoalsRecord.assist2=$record.assist2
$GoalsRecord.situation=$record.situation
$GoalsRecord.pos1=$record.pos1
$GoalsRecord.pos2=$record.pos2
$GoalsRecord.pos3=$record.pos3
$GoalsRecord.pos4=$record.pos4
$GoalsRecord.pos5=$record.pos5
$GoalsRecord.pos6=$record.pos6
$GoalsRecord.neg1=$record.neg1
$GoalsRecord.neg2=$record.neg2
$GoalsRecord.neg3=$record.neg3
$GoalsRecord.neg4=$record.neg4
$GoalsRecord.neg5=$record.neg5
$GoalsRecord.neg6=$record.neg6
if($record.id_team -eq $MatchInfo.team1.id_team){
$A=$A+1
$PlayerName=$MatchInfo.team1.roster | select first_name, last_name |      where {$MatchInfo.team1.roster.id_player -eq $record.goal }
$GoalsRecord.PlayerName = $PlayerName
}

if($record.id_team -eq $MatchInfo.team2.id_team){
$B=$B+1
$PlayerName=$MatchInfo.team1.roster | select first_name, last_name | where {$record.goal -eq $MatchInfo.team1.roster.id_player }
$GoalsRecord.PlayerName = $PlayerName
}

$GoalsRecord.score=$A.ToString()+":"+$B.ToString()

$GoalsTable += ([PSCustomObject]$GoalsRecord)

}

$GoalsTable | Sort score -Descending | Out-GridView -PassThru

0 个答案:

没有答案