我如何以最有效和最安全的方式在groovy中提取:
to: ["example1@example.com", "example2@example.com"], from: "example3@example.com", subject: "example", bodyText: "Hello"
从:
This is an example - to: ["example1@example.com", "example2@example.com"], from: "example3@example.com", subject: "example", bodyText: "Hello"
然后将其转换为Map类型。我试着搜索,但我找不到我正在寻找的东西。任何帮助将非常感激。
答案 0 :(得分:1)
您可以通过在Groovy控制台中运行它来验证此解决方案
def input = 'to: ["example1@example.com", "example2@example.com"], from: "example3@example.com", subject: "example", bodyText: "Hello"'
input = "[$input]"
Map map = Eval.me(input)
assert map.to == ['example1@example.com', 'example2@example.com']
assert map.from == 'example3@example.com'