1 Star 0 Fork 0

天雨流芳 / go-micro-framework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
jsonutil.go 836 Bytes
一键复制 编辑 原始数据 按行查看 历史
天雨流芳 提交于 2024-03-19 15:24 . 增加通用文件
package jsonutil
import (
"fmt"
"gitee.com/tylf2018/go-micro-framework/pkg/common/json"
"strings"
)
type JSONRawMessage []byte
func (m JSONRawMessage) Find(key string) JSONRawMessage {
var objmap map[string]json.RawMessage
err := json.Unmarshal(m, &objmap)
if err != nil {
fmt.Printf("Resolve JSON Key failed, find key =%s, err=%s",
key, err)
return nil
}
return JSONRawMessage(objmap[key])
}
func (m JSONRawMessage) ToList() []JSONRawMessage {
var lists []json.RawMessage
err := json.Unmarshal(m, &lists)
if err != nil {
fmt.Printf("Resolve JSON List failed, err=%s",
err)
return nil
}
var res []JSONRawMessage
for _, v := range lists {
res = append(res, JSONRawMessage(v))
}
return res
}
func (m JSONRawMessage) ToString() string {
res := strings.ReplaceAll(string(m[:]), "\"", "")
return res
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/tylf2018/go-micro-framework.git
git@gitee.com:tylf2018/go-micro-framework.git
tylf2018
go-micro-framework
go-micro-framework
4cc90ded505a

搜索帮助

344bd9b3 5694891 D2dac590 5694891