Home > Web Front-end > JS Tutorial > body text

How to encode and decode JSON in Go language

高洛峰
Release: 2017-02-04 09:52:15
Original
1424 people have browsed it

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)
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!