I have been struggling to figure out how to get a parameter out of a JSON string in Groovy.
I have a string similar to:
'{"id":"12345678","name":"Sharon","email":"sharon\u0040example.com"}'
and am trying to extract the email address.
I can of course use regex, or other substring methods, but I feel like there must be a cleaner way.
解决方案import groovy.json.JsonSlurper
def str = '{"id":"12345678","name":"Sharon","email":"sharon\u0040example.com"}'
def slurper = new JsonSlurper().parseText(str)
assert slurper.email == 'sharon@example.com'
assert slurper.name == 'Sharon'