wangpl_study/day06/json_demo/main.go

21 lines
360 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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)
}