请教一下,用go如何提取这个复杂的yaml

karl_zhao · · 1311 次点击
如3楼所说,tag应放在``内,另外,如果可能的话建议改下yaml格式: ```golang package main import ( "fmt" "gopkg.in/yaml.v2" "os" ) var yamlStr string = ` import: "/testlist.yaml" tests: - test: "xxx_invalid_test" description: > "xxx at a higher priv mode" iterations: 13 ` type Config struct { Import string `yaml:"import"` Tests []struct { Test string `yaml:"test"` Description string `yaml:"description"` Iterations int `yaml:"iterations"` } `yaml:"tests"` } func main() { var c Config err := yaml.Unmarshal([]byte(yamlStr), &c) if err != nil { fmt.Println(err) os.Exit(-1) } fmt.Println(c.Tests[0].Description) } ``` > "xxx at a higher priv mode"
#4
更多评论
你发一下你的yaml文件啊
#1
![image.png](https://static.studygolang.com/201218/d716aad641aa70db2548e23441014b69.png) 就是帖子上面的内容
#2