0
在此代碼中,返回的元素x沒有正文 - 我相信MarshalIndent工作不正常。 我將無法使用結構記錄。 是否有任何解決方法,以便它可以按預期返回值。XML元帥不在此示例中
package main
import "fmt"
import "encoding/xml"
import "time"
type Record struct {
a int64 `xml:"a,omitempty"`
b int64 `xml:"b,omitempty"`
c int64 `xml:"c,omitempty"`
d int64 `xml:"d,omitempty"`
e int64 `xml:"e,omitempty"`
f string `xml:"f,omitempty"`
g string `xml:"g,omitempty"`
h string `xml:"h,omitempty"`
i string `xml:"i,omitempty"`
j string `xml:"j,omitempty"`
k time.Time `xml:"k,omitempty"`
l time.Time `xml:"l,omitempty"`
m string `xml:"m,omitempty"`
n string `xml:"n,omitempty"`
o string `xml:"o,omitempty"`
p int64 `xml:"p,omitempty"`
}
func main() {
temp, _ := time.Parse(time.RFC3339, "")
candiateXML := &Record{1, 2, 3, 4, 5, "6", "7", "8", "9", "10", temp, temp, "13", "14", "15", 16}
fmt.Printf("%v\n", candiateXML.a)
fmt.Printf("%v\n", candiateXML.b)
fmt.Printf("%v\n", candiateXML.c)
fmt.Printf("%v\n", candiateXML.d)
fmt.Printf("%v\n", candiateXML.e)
fmt.Printf("%s\n", candiateXML.f)
fmt.Printf("%s\n", candiateXML.g)
fmt.Printf("%s\n", candiateXML.h)
fmt.Printf("%s\n", candiateXML.i)
fmt.Printf("%s\n", candiateXML.j)
fmt.Printf("%d\n", candiateXML.k)
fmt.Printf("%d\n", candiateXML.l)
fmt.Printf("%s\n", candiateXML.m)
fmt.Printf("%s\n", candiateXML.n)
fmt.Printf("%s\n", candiateXML.o)
fmt.Printf("%v\n", candiateXML.p)
x, err := xml.MarshalIndent(candiateXML, "", " ")
if err != nil {
return
}
//why this is not printing properly
fmt.Printf("%s\n", x)
}
MarshalIndent未返回預期結果。
非常感謝! ++++++++++++++++ –