【发布时间】:2014-11-26 06:49:58
【问题描述】:
我想将一个结构序列化为json,我写了下面的代码,但总是返回空,没弄明白。
您可以在此处尝试以下代码:http://play.golang.org/p/Y7Zv_aFbqs
package main
import (
"encoding/json"
"fmt"
//"io/ioutil"
)
type Configitem struct {
local_address string
local_port int
method string
password string
server string
server_port string
timeout int
}
type GuiConfig struct {
configs []*Configitem
index int
}
func main() {
item1 := &Configitem{
local_address: "eouoeu",
local_port: 111,
method: "eoeoue",
password: "ouoeu",
server: "oeuoeu",
server_port: "qoeueo",
timeout: 3333,
}
config1 := &GuiConfig{
index: 1,
configs: []*Configitem{item1}}
fmt.Println(config1.configs[0].local_address)
res2, err := json.Marshal(config1)
check(err)
fmt.Println(string(res2))
}
func check(e error) {
if e != nil {
panic(e)
}
}
总是返回{},我检查了这个链接http://blog.golang.org/json-and-go,不知道为什么?我的代码有什么问题。
【问题讨论】:
-
是的,我做了一些搜索但还没有找到,谢谢提醒。
标签: go