Best way to code this, string to map conversion in Groovy
- by Daxon
I have a string like
def data = "session=234567893egshdjchasd&userId=12345673456&timeOut=1800000"
I want to convert it to a map
["session", 234567893egshdjchasd]
["userId", 12345673456]
["timeout", 1800000]
This is the current way I am doing it,
def map = [:]
data.splitEachLine("&"){
it.each{ x ->
def object = x.split("=")
map.put(object[0], object[1])
}
}
It works, but is there a more efficient way?