开发者

How to evaluate string in groovy

开发者 https://www.devze.com 2023-02-07 13:26 出处:网络
I have following string: data = [\"myKey\": \"myValue\"] and want to evaluate it as map: def map = evaluate(data)

I have following string:

data = ["myKey": "myValue"]

and want to evaluate it as map:

def map = evaluate(data)

Looks like I'm doing something wrong but I get

groovy.lang.MissingMethodException: No signature of method: DUMMY.evaluate() is

 applicable for argument types: (java.lang.String) v开发者_运维百科alues: [["myKey": "myValue"]]

So my question is how to perform such evaluation?


If I understand your question correctly, you have a String like so:

data = '["myKey": "myValue"]'

If that is the case, you can evaluate it to a Map by using the Eval class

map = Eval.me( data )
0

精彩评论

暂无评论...
验证码 换一张
取 消