如何将invoke-request的结果转为多维数组?

How to convert the result of invoke-request to a multidimensional array?

我用 'Invoke-request' 得到了下面的 JSON。我想将它转换为多维数组。我在网上查看,但找不到合适的解决方案。一个答案会很好,如果没有,那么给我指出适当的资源也会有所帮助。

谢谢

{"ResultForName":
    [{"Name":"work","Values":["no"]},
    {"Name":"location","Values":["\pc\documents"]},
    {"Name":"Authority","Values":["10"]},
    {"Name":"City","Values":["Toronto"]},
    {"Name":"Country","Values":["CA"]},
    {"Name":"Created By","Values":["George"]},
    {"Name":"Money Vault Id","Values":["100000"]},
    {"Name":"Opened  On","Values":["Mark, John, L=Toronto, S=Ontario, C=CA","www.doman.com", O=Office, L=Toronto, S=Ontario, C="CA"]},
                    {"Name":"Driver Name","Values":["Honda"]},
                    {"Name":"Can drive","Values":["0"]},
                    {"Name":"Given Name","Values":["Steven"]},
                    {"Name":"Group Id","Values":["34324"]},
                    {"Name":"Internet System Address","Values"["www.doman.com/Locations"]},
                    {"Name":"Key value","Values":["AXU"]},
                    {"Name":"Key Encryption","Values":["128"]},
                    {"Name":"Last Check up","Values":["12\/20\/2018 04:00:08"]},
                    {"Name":"Last Notification","Values":["11\/22\/2018 05:00:59"]},
                    {"Name":"Last used by","Values":["David"]},
                    {"Name":"Last Used On","Values":["09\/11\/2018 14:57:50"]},
                    {"Name":"Validation","Values":["02\/22\/2019 04:06:18"]},
                    {"Name":"Last Validation query","Values":["Success"]},
                    {"Name":"Last Acceptence","Values":["04\/12\/2019 04:10:11"]},
                    {"Name":"Managed By","Values":["Manager"]},
                    {"Name":"Automatic","Values":["True"]},
                    {"Name":"Options","Values":["More options Needed"]},
                    {"Name":"Organization","Values":["Organization"]},
                    {"Name":"Organizational Unit","Values":["CSV"]},
                    {"Name":"Work Location Date","Values":["02\/29\/2019 02:00:40"]},
                    {"Name":"URL Details","Values":["CN=web.website.com,O=\"Organization\",OU=CSV,L=Toronto,ST=Ontario,C=CA"]},
                    {"Name":"Provence","Values":["Ontario"]},
                    {"Name":"Surname","Values":["Johnson"]},
                    {"Name":"Transaction value","Values":["23452523"]},
                    {"Name":"Validation Acceptance Values",
                                    "Values":["111.11.11.11|443|0|11|0|organization.com\3$","111.11.111.111|443|0|11|0|orgaization.com\2$","111.11.111.111|443|0|11|0|orgaization.com\2$"]},
                    {"Name":"Acceptance  State","Values":["Success"]},
                    {"Name":"Validity Zone","Values":["120"]},
                    {"Name":"ClearMode","Values":["0"]},
                    {"Name":"Approval CA:Count","Values":["1"]},
                    {"Name":"Reader","Values":["Office"]},
                    {"Name":"End Date","Values":[""]},
                    {"Name":"Meeting Subject","Values":["adb.organization.com"]},
                    {"Name":"SubjectAltName DNS","Values":["adb.organization.com","ade.organization.com","Create.orgaization.com"]}],
"Result":1}

JSON中有两行问题:

  • 这行有错位"

{"Name":"Opened On","Values":["Mark, John, L=Toronto, S=Ontario, C=CA","www.doman.com", O=Office, L=Toronto, S=Ontario, C="CA"]},

应该是

{"Name":"Opened On","Values":["Mark, John, L=Toronto, S=Ontario, C=CA","www.doman.com", "O=Office, L=Toronto, S=Ontario, C=CA"]},

  • 还有这一行

{"Name":"Internet System Address","Values"["www.doman.com/Locations"]},

在"Values"

之后应该有一个:

{"Name":"Internet System Address","Values":["www.doman.com/Locations"]},

解决这些问题后,结果有效 JSON 并且可以通过管道传输到 ConvertFrom-JSON:

$JSON = @"
{"ResultForName":
    [{"Name":"work","Values":["no"]},
    {"Name":"location","Values":["\pc\documents"]},
    {"Name":"Authority","Values":["10"]},
    {"Name":"City","Values":["Toronto"]},
    {"Name":"Country","Values":["CA"]},
    {"Name":"Created By","Values":["George"]},
    {"Name":"Money Vault Id","Values":["100000"]},
    {"Name":"Opened  On","Values":["Mark, John, L=Toronto, S=Ontario, C=CA","www.doman.com", "O=Office, L=Toronto, S=Ontario, C=CA"]},
    {"Name":"Driver Name","Values":["Honda"]},
    {"Name":"Can drive","Values":["0"]},
    {"Name":"Given Name","Values":["Steven"]},
    {"Name":"Group Id","Values":["34324"]},
    {"Name":"Internet System Address","Values":["www.doman.com/Locations"]},
    {"Name":"Key value","Values":["AXU"]},
    {"Name":"Key Encryption","Values":["128"]},
    {"Name":"Last Check up","Values":["12\/20\/2018 04:00:08"]},
    {"Name":"Last Notification","Values":["11\/22\/2018 05:00:59"]},
    {"Name":"Last used by","Values":["David"]},
    {"Name":"Last Used On","Values":["09\/11\/2018 14:57:50"]},
    {"Name":"Validation","Values":["02\/22\/2019 04:06:18"]},
    {"Name":"Last Validation query","Values":["Success"]},
    {"Name":"Last Acceptence","Values":["04\/12\/2019 04:10:11"]},
    {"Name":"Managed By","Values":["Manager"]},
    {"Name":"Automatic","Values":["True"]},
    {"Name":"Options","Values":["More options Needed"]},
    {"Name":"Organization","Values":["Organization"]},
    {"Name":"Organizational Unit","Values":["CSV"]},
    {"Name":"Work Location Date","Values":["02\/29\/2019 02:00:40"]},
    {"Name":"URL Details","Values":["CN=web.website.com,O=\"Organization\",OU=CSV,L=Toronto,ST=Ontario,C=CA"]},
    {"Name":"Provence","Values":["Ontario"]},
    {"Name":"Surname","Values":["Johnson"]},
    {"Name":"Transaction value","Values":["23452523"]},
    {"Name":"Validation Acceptance Values",
                    "Values":["111.11.11.11|443|0|11|0|organization.com\3$","111.11.111.111|443|0|11|0|orgaization.com\2$","111.11.111.111|443|0|11|0|orgaization.com\2$"]},
    {"Name":"Acceptance  State","Values":["Success"]},
    {"Name":"Validity Zone","Values":["120"]},
    {"Name":"ClearMode","Values":["0"]},
    {"Name":"Approval CA:Count","Values":["1"]},
    {"Name":"Reader","Values":["Office"]},
    {"Name":"End Date","Values":[""]},
    {"Name":"Meeting Subject","Values":["adb.organization.com"]},
    {"Name":"SubjectAltName DNS","Values":["adb.organization.com","ade.organization.com","Create.orgaization.com"]}],
"Result":1}
"@
$JSON | ConvertFrom-Json