Documentation
¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-12-18 19:09:16 * @FilePath: \go-toolbox\pkg\json\base.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
Index ¶
- Variables
- func AppendKeysToJSONMarshal(originalJSON string, pairs *KeyValuePairs) ([]byte, error)
- func Compact(data []byte) string
- func MarshalWithExtraField(v any, extraKey string, extraValue any) ([]byte, error)
- func ReplaceKeys(data interface{}, oldStr, newStr string) (interface{}, error)
- type KeyValuePairs
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Marshal is exported by go-toolbox/json package. Marshal = json.Marshal // Unmarshal is exported by go-toolbox/json package. Unmarshal = json.Unmarshal // MarshalIndent is exported by go-toolbox/json package. MarshalIndent = json.MarshalIndent // NewDecoder is exported by go-toolbox/json package. NewDecoder = json.NewDecoder // NewEncoder is exported by go-toolbox/json package. NewEncoder = json.NewEncoder )
Functions ¶
func AppendKeysToJSONMarshal ¶
func AppendKeysToJSONMarshal(originalJSON string, pairs *KeyValuePairs) ([]byte, error)
AppendKeysToJSONMarshal 将键值对追加到 JSON 中
func Compact ¶
Compact 将输入的 JSON 字节数组解析并重新编码为紧凑格式的 JSON 字符串。 如果输入不是合法 JSON,或者编码失败,则返回原始字符串。 该函数适用于需要将 JSON 数据以最小化格式存储或传输的场景。
参数:
data - 输入的 JSON 数据,字节切片格式
返回值:
string - 紧凑格式的 JSON 字符串,或原始字符串(当输入不是合法 JSON 时)
func MarshalWithExtraField ¶
MarshalWithExtraField 序列化对象并添加额外字段
func ReplaceKeys ¶
ReplaceKeys 替换 JSON 中的键(key)中的指定字符串为目标字符串
Types ¶
type KeyValuePairs ¶
type KeyValuePairs struct {
// contains filtered or unexported fields
}
KeyValuePairs 是一个用于存储键值对的结构体
func NewKeyValuePairs ¶
func NewKeyValuePairs() *KeyValuePairs
NewKeyValuePairs 创建一个新的 KeyValuePairs 实例
func (*KeyValuePairs) Add ¶
func (kv *KeyValuePairs) Add(key string, value interface{}) *KeyValuePairs
Add 向 KeyValuePairs 中添加一个键值对
Click to show internal directories.
Click to hide internal directories.