Is there a function in golang to encode an array/map using json? Something similar to PHP's json_encode() function is what I'm looking for.
1条回答 默认 最新
- dtrj21373 2016-04-02 06:30关注
you can encode data structures to json in golang using the encoding/json package like this
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) }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报