Json 加载包含哈希表数组的文件失败
从a开始,我一直使用数组和哈希表作为变量从嵌套数据结构中获取值。e、 g.定义Json 加载包含哈希表数组的文件失败,json,powershell,hashtable,powershell-4.0,Json,Powershell,Hashtable,Powershell 4.0,从a开始,我一直使用数组和哈希表作为变量从嵌套数据结构中获取值。e、 g.定义$字段并将其输入选择运算符: $request=http://musicbrainz.org/ws/2/artist/5b11f4ce-a62d-471e-81fc-a69a8278c7da?inc=aliases&fmt=json' $output=Invoke WebRequest$request | convertfromjson $fields=“name”, @{Name='begin';Expression
$字段
并将其输入选择
运算符:
$request=http://musicbrainz.org/ws/2/artist/5b11f4ce-a62d-471e-81fc-a69a8278c7da?inc=aliases&fmt=json'
$output=Invoke WebRequest$request | convertfromjson
$fields=“name”,
@{Name='begin';Expression={$.{life-span}.begin},
@{Name='end';Expression={$.{life-span}.end}
$output |选择$fields
给我:
name begin end
---- ----- ---
Nirvana 1988-01 1994-04-05
并尝试将其导入数组(类似于我之前手动指定的):
$request=http://musicbrainz.org/ws/2/artist/5b11f4ce-a62d-471e-81fc-a69a8278c7da?inc=aliases&fmt=json'
$output=Invoke WebRequest$request | convertfromjson
$runConf=Get Content-Raw-Path bandFields.json | ConvertFrom json
$fields=$runConf.fields
$output |选择$fields
我明白了:
选择:无法将System.Management.Automation.PSObject转换为以下类型之一{System.String,System.Management.Automation.ScriptBlock}
我刚刚用
$runConf=Get Content-Raw-Path bandFields.json | ConvertFrom json
导入了您的json,所以不知道有什么错了问题是$fields现在是一个PSObject,而不是一个数组。在对象中,名为“name”的字段也与其他name属性混淆。这是一种非常不寻常的方式来处理这类事情,我很想完全修改它。