首页 > 解决方案 > 从 JSON API 响应中获取所有元素

问题描述

如下获取 API 响应,并希望使用 reassured 获取所有字段的名称。

{
    "expand": "projects",
    "projects": [
        {
            "expand": "issuetypes",
            "issuetypes": [
                {
                    "subtask": false,
                    "expand": "fields",
                    "fields": {
                        "summary": {
                            "required": true,
                            "schema": {
                                "type": "string",
                                "system": "summary"
                            },
                            "name": "Summary",
                            "hasDefaultValue": false,
                            "operations": [
                                "set"
                            ]
                        },                                               
                        "customfield_10100": {
                            "required": false,
                            "schema": {
                                "type": "any",
                                "custom": "com.pyxis.greenhopper.jira:gh-epic-link",
                                "customId": 10100
                            },
                            "name": "Epic Link",
                            "hasDefaultValue": false,
                            "operations": [
                                "set"
                            ]
                        },                        
                        "customfield_10102": {
                            "required": true,
                            "schema": {
                                "type": "string",
                                "custom": "com.pyxis.greenhopper.jira:gh-epic-label",
                                "customId": 10102
                            },
                            "name": "Epic Name",
                            "hasDefaultValue": false,
                            "operations": [
                                "set"
                            ]
                        },
                       }
                }
            ]
        }
    ]
}

我尝试使用 获取名称respStg1.jsonPath().getList("projects.issuetypes.fields.[*].name"),但出现 gpath 错误。如果有任何方法可以获取 projects.issuetypes.fields 下所有字段的名称,请提供帮助。

标签: javarest-assured

解决方案


试试这个=[*].[*].[*].[*].name 这应该工作将来你可以使用这个链接来评估jsonPath:http: //jsonpath.com/

对于 jsonPath 语法和通配符,请参阅此链接: https: //support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html


推荐阅读