改进gconv.String方法,当无法使用基本类型进行字符串转换时,使用json.Marshal进行转换

This commit is contained in:
John
2018-07-01 19:13:25 +08:00
parent a8d4b21425
commit 31aca3ed1e

View File

@ -15,6 +15,7 @@ import (
"gitee.com/johng/gf/g/encoding/gbinary"
"gitee.com/johng/gf/g/util/gstr"
"gitee.com/johng/gf/g/os/gtime"
"github.com/gin-gonic/gin/json"
)
// 将变量i转换为字符串指定的类型t
@ -117,7 +118,9 @@ func String(i interface{}) string {
case string: return value
case []byte: return string(value)
default:
return fmt.Sprintf("%v", value)
// 默认使用json进行字符串转换
jsonContent, _ := json.Marshal(value)
return string(jsonContent)
}
}