golang 语言常用函数简单介绍
一、格式转换函数
常用格式有数组,字符串,整型,json,map字典,想不到了
import “encoding/json”
各种类型的元素转json格式:
// v 传入结构体、数组等实例变量
// []byte 字节数组
// error 可能会有的错误
func Marshal(v interface{}) ([]byte, error)
各种json格式的数据转其他格式:通过反解析
// []byte 字节数组
// v 传入结构体、数组等实例变量的指针地址
// error 可能会有的错误
func Unmarshal(data []byte, v interface{}) error
数组转json:b, e := json.Marshal(arr2) if e != nil { return }
json转数组:
var a [][]int
json.Unmarshal([]byte(s),&a)