类似PHP json_encode和json_decode 的用法
/* data := map[string]interface{}{ "name": "Tom", "age": 18, "gender": "male", } str, err := JsonEncode(data) */ func JsonEncode(v interface{}) (string, error) { b, err := json.Marshal(v) if err != nil { return "", err } return string(b), nil } /* var decodedData map[string]interface{} err = JsonDecode(str, &decodedData) */ func JsonDecode(s string, v interface{}) error { return json.Unmarshal([]byte(s), v) }
标签:golang,string,err,decode,encode,json,interface From: https://www.cnblogs.com/taoshihan/p/17163613.html