mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-15 04:06:35 +08:00
fix: 数据库实例删除等问题修复
This commit is contained in:
@@ -3,9 +3,8 @@ package jsonx
|
||||
import (
|
||||
"encoding/json"
|
||||
"mayfly-go/pkg/logx"
|
||||
"strings"
|
||||
|
||||
"github.com/buger/jsonparser"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// json字符串转map
|
||||
@@ -42,35 +41,35 @@ func ToStr(val any) string {
|
||||
//
|
||||
// @param fieldPath字段路径。如user.username等
|
||||
func GetStringByBytes(bytes []byte, fieldPath string) (string, error) {
|
||||
return jsonparser.GetString(bytes, strings.Split(fieldPath, ".")...)
|
||||
return gjson.GetBytes(bytes, fieldPath).String(), nil
|
||||
}
|
||||
|
||||
// 根据json字符串获取对应字段路径的string类型值
|
||||
//
|
||||
// @param fieldPath字段路径。如user.username等
|
||||
func GetString(jsonStr string, fieldPath string) (string, error) {
|
||||
return GetStringByBytes([]byte(jsonStr), fieldPath)
|
||||
return gjson.Get(jsonStr, fieldPath).String(), nil
|
||||
}
|
||||
|
||||
// 根据json字节数组获取对应字段路径的int类型值
|
||||
//
|
||||
// @param fieldPath字段路径。如user.age等
|
||||
func GetIntByBytes(bytes []byte, fieldPath string) (int64, error) {
|
||||
return jsonparser.GetInt(bytes, strings.Split(fieldPath, ".")...)
|
||||
return gjson.GetBytes(bytes, fieldPath).Int(), nil
|
||||
}
|
||||
|
||||
// 根据json字符串获取对应字段路径的int类型值
|
||||
//
|
||||
// @param fieldPath字段路径。如user.age等
|
||||
func GetInt(jsonStr string, fieldPath string) (int64, error) {
|
||||
return GetIntByBytes([]byte(jsonStr), fieldPath)
|
||||
return gjson.Get(jsonStr, fieldPath).Int(), nil
|
||||
}
|
||||
|
||||
// 根据json字节数组获取对应字段路径的bool类型值
|
||||
//
|
||||
// @param fieldPath字段路径。如user.isDeleted等
|
||||
func GetBoolByBytes(bytes []byte, fieldPath string) (bool, error) {
|
||||
return jsonparser.GetBoolean(bytes, strings.Split(fieldPath, ".")...)
|
||||
return gjson.GetBytes(bytes, fieldPath).Bool(), nil
|
||||
}
|
||||
|
||||
// 根据json字符串获取对应字段路径的bool类型值
|
||||
|
||||
Reference in New Issue
Block a user