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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Golang 中解組 XML 數(shù)組:只獲取第一個元素

在 Golang 中解組 XML 數(shù)組:只獲取第一個元素

Go
回首憶惘然 2021-09-10 10:41:00
代碼:type HostSystemIdentificationInfo []struct {    IdentiferValue string `xml:"identifierValue"`    IdentiferType  struct {        Label   string `xml:"label"`        Summary string `xml:"summary"`        Key     string `xml:"key"`    } `xml:"identifierType"`}func vsphereHost(v *vsphere.Vsphere, md *opentsdb.MultiDataPoint) error {    res, err := v.Info("HostSystem", []string{        "name",        "summary.hardware.cpuMhz",        "summary.hardware.memorySize", // bytes        "summary.hardware.numCpuCores",        "summary.hardware.numCpuCores",        "summary.quickStats.overallCpuUsage",    // MHz        "summary.quickStats.overallMemoryUsage", // MB        "summary.hardware.otherIdentifyingInfo",        "summary.hardware.model",    })    for _, r := range res {        for _, p := range r.Props {            if p.Name == "summary.hardware.otherIdentifyingInfo" {                var t HostSystemIdentificationInfo                fmt.Println(p.Val.Inner)                err := xml.Unmarshal([]byte(p.Val.Inner), &t)                if err != nil {                    return err                }                fmt.Println(t)            }        }    }所以問題是當我解組時,我只在結果中得到 HostSystemIdentification 結構之一,而不是完整數(shù)組。我該如何解決?這是一個問題減少的去游樂場:http : //play.golang.org/p/5uRJ6Eu8jK
查看完整描述

2 回答

?
茅侃侃

TA貢獻1842條經(jīng)驗 獲得超21個贊

XML 解析器需要具有單個頂級元素的格式良好的 XML 文檔。它正在讀取第一個元素,假設這是整個文檔,然后停在那里。


從元素的父元素開始,HostSystemIdentificationInfo然后對其進行解組:


<whatever>

    <HostSystemIdentificationInfo .../>

    <HostSystemIdentificationInfo .../>

    <HostSystemIdentificationInfo .../>

</whatever>


type HostSystemIdentificationInfo struct {

    IdentifierValue string 

    // ...

}


type whatever struct {

    Info []HostSystemIdentificationInfo `xml:"HostSystemIdentificationInfo"`

}

(如有必要,將 XML 包裝在虛假的頂級元素中)。



查看完整回答
反對 回復 2021-09-10
  • 2 回答
  • 0 關注
  • 451 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號