groovy - 无法通过循环访问 JSONSlurper 数组对象
问题描述
我正在尝试使用 Groovy 访问 Jira Rest API。(而且这个问题不是 Jira 特有的。)
连接没有问题;我可以得到我想要的 JSON 数据。
当我尝试遍历数据中的 JSON 数组时;我失败了。但是,如果我尝试在指定索引处访问 JSON 数组的值;我可以得到数据。
String out_json = get("https://jiraserver.intra/rest/api/2/search/?jql=project%20%3D%20TEST%20ORDER%20BY%20key%20ASC&startAt=0&maxResults=1", authString); // It returns the json data
def out = new JsonSlurper().parseText(out_json)
def key = out.issues[0].key // I can access the key this way
for(int i = 0; i < size; i++){
out.issues[i].key // And it returns null
break;
}
对于不知道 JSON 的人来说,它是这样的:
{
"total": 2,
"issues": [
{
"key": "TEST-1"
-- some other key-values --
},
{
"key": "TEST-2"
-- some other key-values --
}
]
}
我错过了什么?
解决方案
推荐阅读
- azure-devops - Azure DevOps 工作项规则的条件字段值
- java - 从文件中获取输入并将其放入集合中,Java
- compiler-errors - 为什么我的代码没有在 fortran 中编译?
- python - 非常大的数据帧的有效映射
- node.js - 在 MongoDB 聚合中查找具有额外值的项目
- python - 线性规划:如何在 Python 优化中引入第二个决策变量(数组)?
- nlp - 如何使用 GPT-2 进行主题建模?
- php - 对 WooCommerce 中的非“特价”商品应用欢迎折扣
- 2sxc - 在 2sxc 内容类型/视图中向页面添加内容时出错
- jsonnet - 在jsonnet中添加数组元素