java - 从 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 下所有字段的名称,请提供帮助。
解决方案
试试这个=[*].[*].[*].[*].name
这应该工作将来你可以使用这个链接来评估jsonPath:http: //jsonpath.com/
对于 jsonPath 语法和通配符,请参阅此链接: https: //support.smartbear.com/alertsite/docs/monitors/api/endpoint/jsonpath.html
推荐阅读
- firebase - 如何在单个项目中为我的每个 Firebase 站点设置谷歌分析?
- wordpress - WordPress 主题中的航点仅在打开开发人员工具时有效
- c# - 新统一,为什么这个脚本不移动对象?(统一 3D)
- c# - 将自定义反序列化程序发布到 Azure 流分析
- android - Jetpack Navigation NavigationDrawer,菜单项的自定义操作
- r - 这个箱线图缺口正确吗?
- node.js - How to call Terminal Commands in a TEXT File?
- java - 如何创建 Firebase 短动态链接
- artifactory - JCenter maven-metadata.xml 没有来自 Maven Central 的所有模块版本
- avro - 尝试将 JSON 转换为 AVRO 时没有类型错误