鉴于此 JSON
{"name":"//iam.googleapis.com/projects/aw-b9a-8231-4086-a297-ca0/serviceAccounts/1081069135974252","asset_type":"iam.googleapis.com/ServiceAccount","resource":{"version":"v1","discovery_document_uri":"https://iam.googleapis.com/$discovery/rest","discovery_name":"ServiceAccount","parent":"//cloudresourcemanager.googleapis.com/projects/1090951556423","data":{"email":"default@aw-d1eb6b9a-8231-4086-a297-ca0.iam.gserviceaccount.com","name":"projects/aw-d1eb6b9a-8231-4086-a297-ca0/serviceAccounts/default@aw-d1eb6b9a-8231-4086-a297-ca0.iam.gserviceaccount.com","oauth2ClientId":"108102635374252","projectId":"aw-d1eb6b9a-8231-4086-a297-ca0","uniqueId":"108108526913531974252"}},"ancestors":["projects/1090951556423","folders/940897400840","folders/140924730741","organizations/437515948226"],"update_time":"2021-02-08T18:23:18Z"}
我正在尝试使用 Windows 命令窗口中的以下代码段,
powershell -nologo -executionpolicy bypass "& {foreach($line in Get-Content temp.txt) {ConvertFrom-Json -InputObject $line}}" > temp2.txt
将检索到的键和值放入文件 (temp2.txt)。但是,ConvertFrom-Json 只获取 JSON 的第一个层次结构,现在在data
数组中。我试过-Depth 3
但得到这个错误:
At line:1 char:81
+ ... ontent temp.txt) {ConvertFrom-Json -InputObject $line -Depth 4 -Comp ...
+ ~~~~~~
+ CategoryInfo : InvalidArgument: (:) [ConvertFrom-Json], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ConvertFromJsonCommand```