第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

無法將 yaml 文件解組到結(jié)構(gòu)中

無法將 yaml 文件解組到結(jié)構(gòu)中

Go
波斯汪 2023-07-17 14:49:23
我正在嘗試 UnmarshalS 到 DataCollectionFromYAML--- -   labels: cats, cute, funny  name: "funny cats"  url: "http://glorf.com/videos/asfds.com"-   labels: cats, ugly,funny  name: "more cats"  url: "http://glorf.com/videos/asdfds.com"-   labels: dogs, cute, funny  name: "lots of dogs"  url: "http://glorf.com/videos/asasddfds.com"-   name: "bird dance"  url: "http://glorf.com/videos/q34343.com"type DataFromYAML struct {    Labels string `yaml:"labels"`    Name   string `yaml:"name"`    URL    string `yaml:"url"`}type DataCollectionFromYAML struct {    data []VidedFromYAML}這是我的代碼的一部分,我正在使用 gopkg.in/yaml.v2 包yamlFile, err := ioutil.ReadAll(r)    if err != nil {        return err    }    var data models.DataFromYAML    err2 := yaml.Unmarshal(yamlFile, data)我收到錯(cuò)誤消息:無法將 !!seq 解組到 models.DataCollectionFromYAML
查看完整描述

1 回答

?
三國(guó)紛爭(zhēng)

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊

安裝了 包 mainmodels.DataFromYAML的 use 數(shù)組[]models.DataFromYAML


import (

    "fmt"


    "github.com/ghodss/yaml"

)



const data = `--- 

  labels: cats, cute, funny

  name: "funny cats"

  url: "http://glorf.com/videos/asfds.com"

  labels: cats, ugly,funny

  name: "more cats"

  url: "http://glorf.com/videos/asdfds.com"

  labels: dogs, cute, funny

  name: "lots of dogs"

  url: "http://glorf.com/videos/asasddfds.com"

  name: "bird dance"

  url: "http://glorf.com/videos/q34343.com"

`


type DataFromYAML struct {

    Labels string `yaml:"labels"`

    Name   string `yaml:"name"`

    URL    string `yaml:"url"`

}



func main() {

    var test []DataFromYAML

    err := yaml.Unmarshal([]byte(data), &test)

    if err != nil {

        fmt.Printf("err: %v\n", err)

        return

    }


    fmt.Println(test)

}

輸出:


[{cats, cute, funny funny cats http://glorf.com/videos/asfds.com} {cats, ugly,funny more cats http://glorf.com/videos/asdfds.com} {dogs, cute, funny lots of dogs http://glorf.com/videos/asasddfds.com} { bird dance http://glorf.com/videos/q34343.com}]



查看完整回答
反對(duì) 回復(fù) 2023-07-17
  • 1 回答
  • 0 關(guān)注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)