我需要从Powershell中的json读取一些信息。我遇到的问题是,在“路径”部分之后,我无法指定下一个名称,例如调用路径是因为它发生了变化。之后,我需要获取“获取”部分,然后获取“参数”部分,最后获取名称和必填字段。如何在powershell中遍历json而不能指定值。
我可以通过使用$info.host
和$info.paths
这样的路径来获取主机名。然后,我通过遍历路径获取各个路径名,以获取每个名称。
foreach($item in $pName)
{
$item
}
但是,只要我可以得到我尝试使用$ item.childItem,但它不起作用。无论如何要使用像$ item.paths.childItems [$ 1] .get.parameters之类的东西,然后获取名称和所需的字段值?
JSON的是这样的:
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "Requirements.API"
},
"host": "replica.net",
"schemes": [
"http"
],
"paths": {
"/": {
"get": {
"tags": [
"Alive"
],
"operationId": "Alive_Get",
"consumes": [],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Object"
}
}
},
"deprecated": false
}
},
"/requirements/email-docs": {
"get": {
"tags": [
"CustomerRequirement"
],
"operationId": "",
"consumes": [],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "name",
"in": "query",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/UploadResponse"
}
}
}
},
"deprecated": false
}
},