如何将[]byte 转string
type Result struct {
Code string `json:"code"`
Msg string `json:"msg"`
}
func main() {
result:= Result {"100","hello wrod"}
jsonresult, _ := json.Marshal(result)
fmt.Println(string(jsonresult))
}
可以看到golang对象通过json.Marshal成功后会返回[]byte 类型
string(jsonresult)
string函数可以把[]byte类型转换成string
json.Marshal string []byte
如有问题,欢迎大家留言沟通,点赞支持!!