欢迎使用CSDN-markdown编辑器

来源:互联网 发布:数据分析模板 编辑:程序博客网 时间:2024/05/21 11:11

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 Bookerr := json.Unmarshal(b, &book)if err != nil {    fmt.Println(book)}

}

原创粉丝点击