i want to serialize a struct to json, i wrote below code, but always return empty, did not figure it out.
you can try below code here: 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)
}
}
always return {}, i checked this link http://blog.golang.org/json-and-go, did not know why? what's wrong to my code.