Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell-将Json设置为变量_Json_Powershell - Fatal编程技术网

Powershell-将Json设置为变量

Powershell-将Json设置为变量,json,powershell,Json,Powershell,所以我正在进行一个MySQL查询,其中一列是一块json,我想将一个特定的info子集设置为一个变量。想知道我是否能把代码压缩一点。现在我的代码是: $data = Query -Query "select * from TABLE where fqdn = 'testhost.mycompany.com'" $json = $data.request | ConvertFrom-Json $WhatIreallyWant = $json.build_request 我能压缩最后两行吗构建请

所以我正在进行一个MySQL查询,其中一列是一块json,我想将一个特定的info子集设置为一个变量。想知道我是否能把代码压缩一点。现在我的代码是:

$data = Query -Query "select * from TABLE where fqdn = 'testhost.mycompany.com'"

$json = $data.request | ConvertFrom-Json
$WhatIreallyWant = $json.build_request

我能压缩最后两行吗<代码>构建请求是请求json的一部分。

您可以使用这样的管道

$WhatIWant = $data.request | ConvertFrom-Json | Select-Object -ExpandProperty build_request
或者类似于评论中的建议

$WhatIWant = ($data.request | ConvertFrom-Json).build_request 

$WhatIreallyWant=($data.request | ConvertFromJson)。构建请求
?确实如此。谢谢