【发布时间】:2017-12-04 19:10:01
【问题描述】:
我正在尝试从数组中删除整个对象,而不是对象的成员。我无法找到删除对象的方法,有很多解决方案可用于删除该项目。 有人可以建议一种删除完整对象的方法。
JSON Data: JSON data stored in the file.
{
"data": [
{
"id": "Caption",
"firstname": "Caption",
"lastname": "test",
"email": "test",
"requester": "test",
"password": "test",
"incNumber": "test"
}
]
}
Code : I have written the following code to read the object from the array and store into variables to do the task.Once the task is completed I want to remove the object from the array.
$file = Get-Content '\path\to\file' -Raw | ConvertFrom-Json
$file.data | % {if($_.id -eq 'Caption'){
$1 = $_.id
Write-Host $1
###Here I want to remove the whole object related to the id
}}
【问题讨论】:
-
$file.data = $file.data | ? id -ne 'Caption'
标签: json windows powershell powershell-4.0