小编Shu*_*Tao的帖子

如何使用 golang 解析其中的列表 yaml?

示例 yaml 文件final-result.yml

- category: 1
  rules:
  - name: a
    results:
    - asset: b
      advice: c

- category: 2
  rules:
  - name: d
    results:
    - asset: e
      advice: f
Run Code Online (Sandbox Code Playgroud)

我尝试打包gopkg.in/yaml.v2解组:

package main

import (
    "io/ioutil"
    "log"

    "gopkg.in/yaml.v2"
)

type FinalResult struct {
    category string      `yaml:"category"`
    rules    []RulesItem `yaml:"rules,flow"`
}

type RulesItem struct {
    name    string        `yaml:"name"`
    results []ResultsItem `yaml:"results,flow"`
}

type ResultsItem struct {
    asset  string `yaml:"asset"`
    advice string `yaml:"advice"`
}

func main() {
    var result …
Run Code Online (Sandbox Code Playgroud)

yaml go unmarshalling

1
推荐指数
1
解决办法
4997
查看次数

标签 统计

go ×1

unmarshalling ×1

yaml ×1