问题
I have a dictionary that I get as a python dictionary in groovy which I then assign to a variable x :
def x = "{'JIRACHEF': 'PIBEP-2135', 'JIRADEPLOYER': 'PIBEP-2136', 'JIRASINGLEBUILD': 'PIBEP-2137'}"
I want to parse the above and get values for :
- JIRACHEF
- JIRADEPLOYER
- JIRASINGLEBUILD
whats the most elegant groovy way of doing it ?
回答1:
You can use the LAX slurper (in recent versions of Groovy):
import groovy.json.*
def x = "{'JIRACHEF': 'PIBEP-2135', 'JIRADEPLOYER': 'PIBEP-2136', 'JIRASINGLEBUILD': 'PIBEP-2137'}"
def parsed = new JsonSlurper().setType(JsonParserType.LAX).parseText(x)
println parsed.JIRACHEF
println parsed.JIRADEPLOYER
println parsed.JIRASINGLEBUILD
来源:https://stackoverflow.com/questions/41680219/parse-json-in-groovy-to-get-values-python-dict