Try casting the custom object to FooObject
:
$foo = [FooObject](Get-Content 'C:pathoyour.json' | Out-String | ConvertFrom-Json)
If that doesn't work, try constructing the FooObject
instance with the properties of the input object (provided the class has a constructor like that):
$json = Get-Content 'C:pathoyour.json' | Out-String | ConvertFrom-Json
$foo = New-Object FooObject ($json.Foo, $json.Bar, $json.Baz)
If that also doesn't work you need to create an empty FooObject
instance and update its properties afterwards:
$json = Get-Content 'C:pathoyour.json' | Out-String | ConvertFrom-Json
$foo = New-Object FooObject
$foo.AA = $json.Foo
$foo.BB = $json.Bar
$foo.CC = $json.Baz
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…