我想转换一个json
{“测试”:“1,2,3,4”}
进入 yaml 的形式:
---
test:
- 1
- 2
- 3
- 4
为此,我尝试使用以下 groovy 代码段:
def json = new groovy.json.JsonSlurper().parseText('{"test": "1,2,3,4"}')
println json
def ymlMap = json.collectEntries { k, v -> [k , v.split(', ')] }
def yml = new groovy.yaml.YamlBuilder()
yml ymlMap
println yml.toString()
但它打印
---
test:
- "1,2,3,4"
任何提示如何正确使用 yamlbuilder?