【发布时间】:2020-06-26 21:48:51
【问题描述】:
我正在尝试访问以下 json 中 OperationId 的所有值并将其添加到数组中,但是当我深入研究数据时,它一直给我一个空异常。下面是 json,任何关于我如何直接访问 operationIds 的建议都非常感谢。
注意:所有控制器名称和 HttpVerbs 在整个 json 中都是可变的,这只是 10,000 行 Json 文件的一小部分,因此硬编码每个值以获取字符串是行不通的。
json:
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "API Services"
},
"host": "TestApi.Com",
"basePath": "/TestApi",
"schemes": ["https"],
"paths": {
"/activity/actions": {
"get": {
"tags": ["activities"],
"summary": "Returns a list of non-hidden Actions.",
"description": "Test Description",
***"operationId": "GET/activity/actions", //Need to add this to array***
"consumes": [],
"produces": ["application/json", "text/json", "application/xml", "text/xml"],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/ActionResponse"
}
}
}
}
},
"put": {
"tags": ["activities"],
"summary": "Updates any/all existing ActivityActions by matching Id",
"description": "Test Description",
***"operationId": "PUT/activity/actions", //Need to add this to array***
"consumes": ["application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded"],
"produces": ["application/json", "text/json", "application/xml", "text/xml"],
"parameters": [{
"name": "List`1",
"in": "body",
"required": true,
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/ActivityActionPutRequest"
}
}
}, {
"name": "Authorization",
"in": "header",
"description": "AccessToken",
"required": false,
"type": "string"
}],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/ActivityActionUpdateResponse"
}
}
}
}
}
},
"/activity/agency-url/create": {
"get": {
"tags": ["activities"],
"summary": "Test",
***"operationId": "GET/activity/agency-url/create", //Need to add this to array***
"consumes": [],
"produces": ["application/json", "text/json", "application/xml", "text/xml"],
"parameters": [{
"name": "EntityType",
"in": "query",
"description": "Test",
"required": true,
"type": "string"
}, {
"name": "EntityId",
"in": "query",
"description": "The Guid or Sequence No of the entity.",
"required": true,
"type": "string"
}, {
"name": "Authorization",
"in": "header",
"description": "AccessToken",
"required": false,
"type": "string"
}],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ActivityUrlResponse"
}
}
}
}
}
}
}
所以输出看起来像:
[GET/activity/actions, PUT/activity/actions, GET/activity/agency-url/create]
【问题讨论】:
标签: c# json json.net json-deserialization