更新时间:2023-11-14 09:55:34
您可以在.
上分割路径(用正则表达式引用),然后减少在路径上使用您的数据.例如
You can split the path on .
(quote it for the regexp) and then reduce
over the path using your data. E.g.
def data = [a: [b: [c: 42]]]
def path = "a.b.c"
println path.split(/\./).inject(data){ m, p -> m?.getAt(p) }
// → 42