Home > Article > Web Front-end > How to encode and decode JSON in Go language
The example in this article describes the method of encoding and decoding JSON in Go language. Share it with everyone for your reference. The details are as follows:
json has become the best way to transmit data between different platforms. Golang has very good support for json. The code is as follows:
package main import ( "fmt" "encoding/json" ) func main() { // json encode j1 := make(map[string]interface{}) j1["name"] = "脚本之家" j1["url"] = "http://www.jb51.net/" js1, err := json.Marshal(j1) if err != nil { panic(err) } println(string(js1)) // json decode j2 := make(map[string]interface{}) err = json.Unmarshal(js1, &j2) if err != nil { panic(err) } fmt.Printf("%#v\n", j2) }
I hope that this article will be useful for everyone’s Go language programs. Design helps.
For more related articles on how to encode and decode JSON in Go language, please pay attention to the PHP Chinese website!