我有像YAML一样的
data:
label1:
- someval1
- someval2
label2:
- otherval1
- otehrval2
使用YAML解析器" gopkg.in/yaml.v2"
yaml.Unmarshal([]byte(yamlStr), &yamlObj)
# Some works and changes to yamlObj
s, _ := yaml.Marshal(&yamlObj)
fmt.Println(string(s))
输出:
data:
label1:
- someval1
- someval2
label2:
- otherval1
- otehrval2
结果YAML是正确的但是对于我的任务,我需要在原始YAML中缩进列表(- values
)。有没有办法保留这些空格和新线?