我尝试循环下面的json对象以获取"x-visibility":"Public所选的输出需要写入一个新的json文件中。
我试图在“路径”上使用ForEach-Object,如何迭代"/about“和etc并获取"x-visibility”对象?
{
"swagger": "2.0",
"info": {
"title": "Ope sepc API",
"version": "20.8.0"
},
"basePath": "/qrs",
"schemes": [
"https"
],
"paths": {
"/about": {
"get": {
"operationId": "65d540ef-b3b9-4678-ae24-2d8abdc304cc",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/About"
}
}
},
"x-visibility": "Public",
"x-stability": "Locked"
}
},
"/about/api/default": {
"get": {
"operationId": "3d1a3502-a020-4a37-8da3-90b7e030792e",
"parameters": [
{
"name": "listentries",
"in": "query",
"required": false,
"default": true,
"type": "boolean",
"allowEmptyValue": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object",
"additionalProperties": {
"type": "object"
}
}
}
}
]
}
}
}
"x-visibility": "Private",
"x-stability": "Locked"
}
},
"/about/api/default/analyticconnection": {
"get": {
"operationId": "2b781738-afd0-37a9-4248-84ec8d6be58c",
"parameters": [
{
"name": "listentries",
"in": "query",
"required": false,
"default": true,
"type": "boolean",
"allowEmptyValue": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/AnalyticConnection"
}
}
},
"x-visibility": "Public",
"x-stability": "Locked"
}
},
"/about/api/default/app": {
"get": {
"operationId": "f868fb6f-330f-60f8-0851-60eadf848788",
"parameters": [
{
"name": "listentries",
"in": "query",
"required": false,
"default": true,
"type": "boolean",
"allowEmptyValue": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/App"
}
}
},
"x-visibility": "Private",
"x-sability": "Locked"
}
},
"/about/api/default/app/content": {
"get": {
"operationId": "4d486f37-c652-85bb-c291-a7384cccdfad",
"parameters": [
{
"name": "listentries",
"in": "query",
"required": false,
"default": true,
"type": "boolean",
"allowEmptyValue": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/AppContent"
}
}
},
"x-visibility": "Public",
"x-stability": "Locked"
}
},
我必须在powershell中完成所有这些工作,并且我不熟悉powershell脚本的世界。如果可能,请提供帮助
发布于 2018-06-02 22:23:15
请修复您的JSON。以下代码应该可以执行您想要的操作:
foreach ($p in $data.paths.psobject.properties.value) { $p.get }
PSObject.Properties
会给你一个对象上所有属性的列表。
https://stackoverflow.com/questions/50657246
复制相似问题