mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-31 03:46:34 +08:00
feat: 代码优化、机器计划任务完善
This commit is contained in:
26
server/pkg/utils/jsonx/jsonx.go
Normal file
26
server/pkg/utils/jsonx/jsonx.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package jsonx
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"mayfly-go/pkg/global"
|
||||
)
|
||||
|
||||
// json字符串转map
|
||||
func ToMap(jsonStr string) map[string]any {
|
||||
var res map[string]any
|
||||
if jsonStr == "" {
|
||||
return res
|
||||
}
|
||||
_ = json.Unmarshal([]byte(jsonStr), &res)
|
||||
return res
|
||||
}
|
||||
|
||||
// 转换为json字符串
|
||||
func ToStr(val any) string {
|
||||
if strBytes, err := json.Marshal(val); err != nil {
|
||||
global.Log.Error("toJsonStr error: ", err)
|
||||
return ""
|
||||
} else {
|
||||
return string(strBytes)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user