我有一个代码如下
import groovy.yaml.YamlSlurper
def configYaml = '''\
---
application: "Sample App"
users:
- name: "mrhaki"
likes:
- Groovy
- Clojure
- Java
- name: "Hubert"
likes:
- Apples
- Bananas
connections:
- "WS1"
- "WS2"
'''
// Parse the YAML.
def config = new YamlSlurper().parseText(configYaml)
def data1 = "users"
def date2 = "name"
println config.users.likes // printing correct
println config.$data1.$data2 // getting error
我需要打印www.example.com中的元素users.name,并且需要从变量形式打印它。例如“println config.$data1.$data2”
1条答案
按热度按时间mwecs4sa1#
你可以做一些像下面。