相关疑难解决方法(0)

我的结构不是编组到json中

我在Mac OS X 10.8.2上使用Go 1.0.3,我正在试验json包,尝试将结构封送到json,但我不断得到一个空的{}json对象.

err值是零,所以没有什么根据的是错误的json.Marshal功能,并且该结构是正确的.为什么会这样?

package main

import (
  "encoding/json"
  "fmt"
)

type Address struct {
  street string
  extended string
  city string
  state string
  zip string
}

type Name struct {
  first string
  middle string
  last string
}

type Person struct {
  name Name
  age int
  address Address
  phone string
}

func main() {
  myname := Name{"Alfred", "H", "Eigenface"}
  myaddr := Address{"42 Place Rd", "Unit 2i", "Placeton", "ST", "00921"}
  me := …
Run Code Online (Sandbox Code Playgroud)

json go

17
推荐指数
2
解决办法
1504
查看次数

标签 统计

go ×1

json ×1