我有一个带有字符串和 int 的简单结构。当我解组 json 时,如果以小写字符串开头,则不会解析结构成员。即使我在同一个包中使用package mainimport ( "encoding/json" "fmt")type Bird struct { Species string Description string lifespan int}func main() { birdJson := `{"species": "pigeon","description": "likes to perch on rocks","lifespan": 9}` var bird Bird json.Unmarshal([]byte(birdJson), &bird) fmt.Printf("Species: %s, Description: %s,lifespan: %d", bird.Species, bird.Description,bird.lifespan) //Cant read the lifespan ??}
- 1 回答
- 0 关注
- 103 浏览
添加回答
举报
0/150
提交
取消