package main
import (
“encoding/json”
“fmt”
)
type Book struct {
Title string
Authors []string
Publisher string
IsPublished bool
Price float32
}
func main() {
Authors := []string{"XuShiwei", "HughLv", "Pandaman", "GuaguaSong", "HanTuo", "BertYuan", "XuDaoli"}
gobook := Book {
"Go语言编程",
Authors,
"ituring.com.cn",
true,
9.99,
}
// 将一个结构体转换为 json 对象
b, _ := json.Marshal(gobook)
//fmt.Println(string(b))
var book Book
err := json.Unmarshal(b, &book)
if err != nil {
fmt.Println(book)
}
}