wangpl_study/day06/json_demo/main.go

21 lines
360 B
Go
Raw Permalink Normal View History

2024-10-21 15:54:36 +08:00
package main
import (
"encoding/json"
"fmt"
)
//json
type person struct {
Name string `json:"name"`
Age int `json:"age"`
}
func main() {
str := `{"name":"周林","age":9000}`
var p person
json.Unmarshal([]byte(str), &p) //注意这里传值要对应传递结构体类型根据结构体的key去对应匹配value
fmt.Println(p.Name, p.Age)
}