我有这个JSON对象,在PowerShell中嵌套了“Items”,我想使用递归函数遍历所有对象
[
{
"name": "Introduction",
"href": "introduction.md"
},
{
"name": "Definitions and schema",
"href": "definition-and-schema/intro.md",
"items": [
{
"name": "Entity definitions",
"href": "definition-and-schema/entity-definitions/intro.md",
"items": [
{
"name": "Entity definitions page",
"href": "definition-and-schema/entity-definitions/entity-definitions.md"
},
{
"name": "Create a new Entity definition",
"href": "definition-and-schema/entity-definitions/create-entity-definition.md"
},
{
"name": "Member groups",
"href": "definition-and-schema/entity-definitions/member-groups.md"
},
{
"name": "Members",
"href": "definition-and-schema/entity-definitions/members/intro.md",
"items": [
{
"name": "Adding a property",
"href": "definition-and-schema/entity-definitions/members/adding-property.md"
},
{
"name": "Adding a relation",
"href": "definition-and-schema/entity-definitions/members/adding-relation.md"
},
{
"name": "Adding a taxonomy",
"href": "definition-and-schema/entity-definitions/members/adding-taxonomy.md"
}
]
}
]
}
]
}
]
我正在使用ConvertFrom-json检索json对象
$jsonObject = ConvertFrom-Json $JsonString
2条答案
按热度按时间bvn4nwqk1#
以下代码片段递归地遍历对象图并处理每个
"items"
属性值:dgtucam12#
递归地查找(和/或替换)PowerShell对象中的节点的常见可重用函数:
使用方法
查找具体节点的值:
在哈希表的情况下:
警告:与PowerShell的正常行为不同,哈希表kay区分大小写。
另请参阅:
#14143
JSON auto-parse is case insensitive替换特定节点的所有值:
结果