我尝试过滤一个列表,只显示包含"Total Votes"
键的数据,但得到的结果是空的。下面是代码:
import org.apache.log4j.Logger;
import java.net.HttpURLConnection;
import org.json.JSONObject;
import org.apache.log4j.Level;
Logger log = Logger.getLogger("za.co.jira.groovy")
// Get the Change History for the issue key specified above
def issue = get("/rest/api/3/issue/${issue.key}/changelog")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
//Save the results as a map
def issueResult = issue.values.items as List<Map>
logger.info("Issue details:" + issueResult.findAll{it.field == 'Total Votes'
issueResult
变量的输出为
[
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "2",
"to": null,
"toString": "3"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "3",
"to": null,
"toString": "2"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "2",
"to": null,
"toString": "3"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "3",
"to": null,
"toString": "4"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "4",
"to": null,
"toString": "3"
}]
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "3",
"to": null,
"toString": "4"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "4",
"to": null,
"toString": "3"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "3",
"to": null,
"toString": "4"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "4",
"to": null,
"toString": "3"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "3",
"to": null,
"toString": "0"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "0",
"to": null,
"toString": "1"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "1",
"to": null,
"toString": "0"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "0",
"to": null,
"toString": "1"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "0",
"to": null,
"toString": "1"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "1",
"to": null,
"toString": "0"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "1",
"to": null,
"toString": "0"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "10020",
"toString": "Done"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Total Votes",
"fieldtype": "custom",
"fieldId": "customfield_10067",
"from": null,
"fromString": "0",
"to": null,
"toString": "1"
}],
[{
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Voting Process Status",
"fieldtype": "custom",
"fieldId": "customfield_10073",
"from": null,
"fromString": null,
"to": "10121",
"toString": "Open"
}, {
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}],
[{
"field": "Voting Process Status",
"fieldtype": "custom",
"fieldId": "customfield_10073",
"from": "10120",
"fromString": "Closed",
"to": "10121",
"toString": "Open"
}, {
"field": "Operation",
"fieldtype": "custom",
"fieldId": "customfield_10074",
"from": null,
"fromString": null,
"to": "10123",
"toString": "Single"
}, {
"field": "status",
"fieldtype": "jira",
"fieldId": "status",
"from": "3",
"fromString": "In Progress",
"to": "3",
"toString": "In Progress"
}]
]
但logger.info给出的结果为空[]
1条答案
按热度按时间2lpgd9681#
这个问题来自于项目的所有嵌套(列表中的1个对象在列表中的一个对象中)。我使用了groovy的
JsonSlurper
而不是org.json.JSONObject
,类似这样的东西应该可以工作,最后你得到了一个所需的List<Map>
: