Groovy ConfigSlurper 配置数组
我正在尝试创建一个如下所示的配置:
nods = [
nod {
test = 1
},
nod {
test = 2
}
]
然后使用 configSlurper 读取它,但“节点”对象在读取后似乎为空。
这是我的代码:
final ConfigObject data = new ConfigSlurper().parse(new File("config.dat").toURI().toURL())
println data.nods
和输出:
[null, null]
我做错了什么?
谢谢!
I am trying to create a config that would look something like this:
nods = [
nod {
test = 1
},
nod {
test = 2
}
]
and then use configSlurper to read it but the "node" objects appear to be null after the read.
Here is my code:
final ConfigObject data = new ConfigSlurper().parse(new File("config.dat").toURI().toURL())
println data.nods
and the output:
[null, null]
What am I doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它认为我是这样解决的:
然后使用它:
希望这对其他人有帮助!
It think I resolved it this way:
And then using it like:
Hope this helps someone else!!
在使用 ConfigSlurper 做此类事情时必须小心。
例如,您的解决方案实际上会产生以下输出:
如果您仔细观察,您会注意到第二个数组值 flase 上有一个拼写错误,而不是 false
以下:
应该产生正确的结果:
You have to be careful when using ConfigSlurper when doing this sort of thing.
For example your solution will actually produce the following output:
If you look carefully you will notice that there is a typo on the second array value flase instead of false
The following:
should produce the correct result:
我尝试用 ConfigSlurper 解析如下内容:
数组“sha”与预期相距甚远。
为了将“sha”作为 ConfigObjects 数组获取,我使用了一个助手:
这样我就得到了 ConfigObjects 数组:
I tried to parse with ConfigSlurper something like this:
The array "sha" was far from what expected.
To get "sha" as an array of ConfigObjects I used a helper:
this way I get an array of ConfigObjects: