java - using eval in groovy -


how can use eval in groovy evaluate following string:

{key1=keyval, key2=[listitem1, listitem2], key3=keyval2}

all list items , keyval string.

doing eval.me("{key1=keyval, key2=[listitem1, listitem2], key3=keyval2}") giving me following error:

ambiguous expression either parameterless closure expression or isolated open code block; solution: add explicit closure parameter list, e.g. {it -> ...}, or force treated open block giving label, e.g. l:{...} at

i want hashmap

you can parse string translating of characters, , writing own binding return variable names when groovy tries them up, so:

class evaluator extends binding {   def parse( s ) {     groovyshell shell = new groovyshell( );     shell.evaluate( s )   }   object getvariable( string name ) { name } }  def instr = '{key1=keyval, key2=[listitem1, listitem2], key3=keyval2}' def inobj = new evaluator().parse( instr.tr( '{}=', '[]:' ) )  println inobj 

but very brittle solution, , getting data in friendlier format (as suggested @stefan) best way go...


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -