我有一个带有字符串和 int 的简单结构。当我解组 json 时,如果以小写字符串开头,则不会解析结构成员。即使我在同一个包中使用
package main
import (
"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 ??
}
心有法竹
相关分类