如何编写一些 groovy 脚本来返回按嵌套在键中的键name
排序的名称数组 () ?created_at
commit
使用它作为样本数据:
[
{"name":"v10.8.0-rc13",
"message":"Version v10.8.0-rc13",
"target":"171b50a40984c358a07c7e37ee95f8d788718198",
"commit":
{
"id":"1b3911c3cc8e72cc93370a90a597e2a0b944bcc2",
"short_id":"1b3911c3",
"title":"Update VERSION to 10.8.0-rc13",
"created_at":"2018-05-18T12:43:58.000+01:00", <------ I WANT TO SORT BY THIS
"parent_ids":["a7090d00098a4acc03cfc2b01df8019c918bd0bc"],
"message":"Update VERSION to 10.8.0-rc13\n",
"author_name":"Filipa Lacerda",
"author_email":"filipa@gitlab.com",
"authored_date":"2018-05-18T12:43:58.000+01:00",
"committer_name":"Filipa Lacerda",
"committer_email":"filipa@gitlab.com",
"committed_date":"2018-05-18T12:43:58.000+01:00"
},
"release":null
},
.
.
.
]
到目前为止,我正在使用这样的东西来获取未排序的名称列表:
List<String> tags= new ArrayList<String>()
def url="curl -X GET http://blah_blah"
def payload = url.execute().text
def slurper = new JsonSlurper()
def response = slurper.parseText(payload)
for(item in response)
{
tags.add(item.name)
}
println(tags)
在这种情况下,response
是类型java.util.ArrayList
并且response[0]
是类型groovy.json.internal.LazyMap
到目前为止,我发现的所有示例都使用.sort
or.SortBy
方法在LazyMap
. **更新**我不认为这是一个真实的陈述。