1

我有一个 PS 自定义对象:

TourCode           : s
TournamentNumber   : 524
TournamentName     : Mitsubishi Electric Championship at Hualalai
EnvironmentType    : PGA Tour
TournamentRootPath : /mitsubishi-electric-championship-at-hualalai
SValues            : {@{S1=championstour; S2=tournaments; S3=mitsubishi-electric-championship-at; S4=}}

我可以轻松地修改 TourCode 或 TournamentName 等顶级属性的值:

PS C:\Users\yuriy> $testTournament.TourCode = 'r'

PS C:\Users\yuriy> $testTournament

TourCode           : r
TournamentNumber   : 524
TournamentName     : Mitsubishi Electric Championship at Hualalai
EnvironmentType    : PGA Tour
TournamentRootPath : /mitsubishi-electric-championship-at-hualalai
SValues            : {@{S1=championstour; S2=tournaments; S3=mitsubishi-electric-championship-at; S4=}}

但是在尝试修改 SValues 属性中的属性 S1、S2、S4 或 S4 时,我遇到了奇怪的错误消息:

PS C:\Users\yuriy> $testTournament.SValues.S3 = 'newvalue'
The property 'S3' cannot be found on this object. Verify that the property exists and can be set.
At line:1 char:1
+ $testTournament.SValues.S3 = 'newvalue'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException

为什么它说它找不到该属性?我可以通过这样引用它来轻松获得它的价值:

PS C:\Users\yuriy> $testTournament.SValues.S3
mitsubishi-electric-championship-at

我究竟做错了什么?

UPD:gm -i $testTournament.SValues的输出在屏幕截图上:http: //i.imgur.com/BeRr2aJ.png JSON 片段在屏幕截图上: http: //i.imgur.com/BBK2nsi.png(类似数据) 使用以下代码读取和转换 JSON 文件:

$testData = Get-Content -Raw -Path "Test Data.json" | ConvertFrom-Json

然后创建 $testTournament:

$testTournament = $testData.Tournaments | Get-Random
4

0 回答 0