I write the program in the 1111.txt.The purpose of this progaram is to marshal the structure,unmarshal it and output some result.But I can't output the marshal result and there are some errors exist .How to solve it??Thank you for reading. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
package main import ( "encoding/json" "fmt" ) type Book struct { Title string Authors []string Publisher string IsPublisehed bool Price float64 } func main() { orgbook := Book{ "Go语言编程", {"xushiwei", "hughlv", "pandaman", "guangsong"}, "ituring.com.cn", true, 9.99} b, err := json.Marshal(orgbook) if err != nil { fmt.Println(err) } fmt.Println(string(b)) gobook := []byte(`{ "Title":"Go语言编程", "Authors":["xushiwei","hughlv", "pandaman","guangsong"], "Publisher":"ituring.com.cn", "IsPublished":true, "Price":9.99, "Sales":1000000 }`) var r interface{} err = json.Unmarshal(gobook, &r) if err != nil { fmt.Println(err) } //b, err := json.Marshal(gobook) //fmt.Println(gobook) //fmt.Println(b) gobook11, ok := r.(map[string]interface{}) if ok { for k, v := range gobook11 { switch v2 := v.(type) { case string: fmt.Println(k, "is a string:", v2) case int: fmt.Println(k, "is int:", v2) case bool: fmt.Println(k, "is bool:", v2) case []interface{}: fmt.Println(k, "is an array:") for i, iv := range v2 { fmt.Println(i, iv) } default: fmt.Println(k, "is another type:") } } } }