我需要从Powershell中的json阅读一些信息。我遇到的问题是,在“路径”部分之后,我无法指定下一个名称,例如路径被称为是因为它改变了。然后,在那之后,我需要获取“get”部分,然后获取“parameters”部分,最后在此获取名称和必填字段。
我可以通过使用$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
}
},
最佳答案
我用这个得到它:
for($i=0;$i-lt$pName.Count;$i++)
{
$test | Select -ExpandProperty paths | select -ExpandProperty $pName[$i] | select -ExpandProperty get
}
关于json - 如何在PowerShell中通过json进行迭代而又无法指定值。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44263318/