3
golang中有使用json編碼數組/地圖的函數嗎?類似於PHP的json_encode()函數是我正在尋找的。有沒有使用json編碼數組/地圖的函數?
golang中有使用json編碼數組/地圖的函數嗎?類似於PHP的json_encode()函數是我正在尋找的。有沒有使用json編碼數組/地圖的函數?
你可以編碼數據結構使用編碼/ JSON包這樣
package main
import (
"encoding/json"
"fmt"
"os"
)
func main() {
group := map[string]interface{} {
"name": "John Doe",
"age": 112,
}
b, err := json.Marshal(group) // this converts the structure into json
if err != nil {
fmt.Println("error:", err)
}
os.Stdout.Write(b)
}
在golang到JSON我強烈建議通過https://godoc.org/-/go去和https://golang.org/doc/effective_go.html – OneOfOne