mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
25 lines
433 B
Go
25 lines
433 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"mayfly-go/pkg/global"
|
|
)
|
|
|
|
func Json2Map(jsonStr string) map[string]interface{} {
|
|
var res map[string]interface{}
|
|
if jsonStr == "" {
|
|
return res
|
|
}
|
|
_ = json.Unmarshal([]byte(jsonStr), &res)
|
|
return res
|
|
}
|
|
|
|
func ToJsonStr(val any) string {
|
|
if strBytes, err := json.Marshal(val); err != nil {
|
|
global.Log.Error("toJsonStr error: ", err)
|
|
return ""
|
|
} else {
|
|
return string(strBytes)
|
|
}
|
|
}
|