From 1e70d9f8938d42dfff11538792c4aa5bf9045ba1 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 3 Nov 2020 17:22:58 +0800 Subject: [PATCH] 1 --- strutils.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/strutils.go b/strutils.go index 988f329..c709ea0 100644 --- a/strutils.go +++ b/strutils.go @@ -1,10 +1,13 @@ package q5 -import "io" -import "strings" -import "crypto/md5" -import "encoding/hex" -import "hash/crc32" +import ( + "io" + "strings" + "crypto/md5" + "encoding/hex" + "encoding/json" + "hash/crc32" +) const ( JSON_NONE = 0 @@ -45,3 +48,11 @@ func JsonStrType(data string) int32 { } } } + +func EncodeJson(p interface{}) string { + if jsonBytes, err := json.Marshal(p); err == nil { + return string(jsonBytes) + } else { + return "" + } +}