Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.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 选择对象空错误?_Powershell - Fatal编程技术网

Powershell 选择对象空错误?

Powershell 选择对象空错误?,powershell,Powershell,我试图从以下json服务器响应中选择“num”和“list”字段: [{"num":"3-4-5-3-2","list":[]},{"num":"1-7-43-2-221","list":[]}] 下面是我使用选择对象命令所做的尝试: $content = [{"num":"3-4-5-3-2","list":[]},{"num":"1-7-43-2-221","list":[]}] $stuff = $content | Select-Object num, list 但是,当我尝试从$s

我试图从以下json服务器响应中选择“num”和“list”字段:

[{"num":"3-4-5-3-2","list":[]},{"num":"1-7-43-2-221","list":[]}]
下面是我使用
选择对象
命令所做的尝试:

$content = [{"num":"3-4-5-3-2","list":[]},{"num":"1-7-43-2-221","list":[]}]
$stuff = $content | Select-Object num, list
但是,当我尝试从
$stuff.num
获取信息时(打印数值,计算有多少个'num'实例等),我得到一个错误:
您不能对空值表达式调用方法
-引用
$stuff.num


因此,当指定对象存在多个实例时,调用
Select Object
命令将导致指针(
num
)为空。如何解决此错误以获取所有
num
实例及其值的工作列表/数组/任何内容?

您是否尝试过使用ConvertFrom Json,然后使用Select Object

$Stuff = $ServerResponse | ConvertFrom-Json | Select-Object num, list
$Stuff.num

ConvertFrom Json
参数应该是什么?它只有一个参数:
-InputObject
,在我的示例中,当您通过它传递数据时使用该参数。不能说我使用它作为命名参数,但可以想象它仍然可以工作。