首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >迭代Json对象以获取Powershell中的3级数据

迭代Json对象以获取Powershell中的3级数据
EN

Stack Overflow用户
提问于 2018-06-02 21:07:30
回答 1查看 128关注 0票数 0

我尝试循环下面的json对象以获取"x-visibility":"Public所选的输出需要写入一个新的json文件中。

我试图在“路径”上使用ForEach-Object,如何迭代"/about“和etc并获取"x-visibility”对象?

代码语言:javascript
复制
{
  "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脚本的世界。如果可能,请提供帮助

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-02 22:23:15

请修复您的JSON。以下代码应该可以执行您想要的操作:

代码语言:javascript
复制
 foreach ($p in $data.paths.psobject.properties.value) { $p.get }

PSObject.Properties会给你一个对象上所有属性的列表。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50657246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档