如何利用golang
语法如何建json转字符串格式,下面web建站小编给大家简单介绍一下具体实现方法!
json格式:
{ "name": "小米", "age": 32, "sex": 男, "isStudent": true, "hobbies": ["reading", "swimming", "traveling"] }
实现代码:
import ( "encoding/json" "fmt" ) func main() { data := map[string]interface{}{ "name": "小米", "age": 32, "isStudent": true, "hobbies": []string{"reading", "swimming", "traveling"}, } result, err := json.Marshal(data) if err != nil { panic(err) } fmt.Println(string(result)) }
输出结果:
{"age":32,"hobbies":["reading","swimming","traveling"],"isStudent":true,"name":"小米"}
标签: golang语法, json转string, json转字符串
上面是“golang语法如何建json转字符串”的全面内容,想了解更多关于 后端开发 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_4477.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!