jsonKit

package
v2.8.168 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetField func(jsonData []byte, path string) gjson.Result = gjson.GetBytes

GetField

@param path 如果是嵌套的内部字段,可以通过'.'组合

字段类型判断:

Result.Type
Result.IsBool()
Result.IsArray()
Result.IsObject()
View Source
var GetFieldFromString func(json, path string) gjson.Result = gjson.Get

Functions

func GetBoolField added in v2.1.52

func GetBoolField(jsonData []byte, path string) bool

func GetBoolFieldFromString added in v2.1.52

func GetBoolFieldFromString(jsonStr, path string) bool

func GetBoolSliceField added in v2.1.52

func GetBoolSliceField(jsonData []byte, path string) (s []bool)

func GetBoolSliceFieldFromString added in v2.1.52

func GetBoolSliceFieldFromString(jsonStr, path string) (s []bool)

func GetFloat64Field added in v2.1.52

func GetFloat64Field(jsonData []byte, path string) float64

func GetFloat64FieldFromString added in v2.1.52

func GetFloat64FieldFromString(jsonStr, path string) float64

func GetFloat64SliceField added in v2.1.52

func GetFloat64SliceField(jsonData []byte, path string) (s []float64)

func GetFloat64SliceFieldFromString added in v2.1.52

func GetFloat64SliceFieldFromString(jsonStr, path string) (s []float64)

func GetInt64Field added in v2.1.52

func GetInt64Field(jsonData []byte, path string) int64

func GetInt64FieldFromString added in v2.1.52

func GetInt64FieldFromString(jsonStr, path string) int64

func GetInt64SliceField added in v2.1.52

func GetInt64SliceField(jsonData []byte, path string) (s []int64)

func GetInt64SliceFieldFromString added in v2.1.52

func GetInt64SliceFieldFromString(jsonStr, path string) (s []int64)

func GetLibrary added in v2.1.52

func GetLibrary() string

func GetStringField added in v2.1.52

func GetStringField(jsonData []byte, path string) string

func GetStringFieldFromString added in v2.1.52

func GetStringFieldFromString(jsonStr, path string) string

func GetStringSliceField added in v2.1.52

func GetStringSliceField(jsonData []byte, path string) (s []string)

func GetStringSliceFieldFromString added in v2.1.52

func GetStringSliceFieldFromString(jsonStr, path string) (s []string)

func Marshal

func Marshal(v interface{}) ([]byte, error)

func MarshalIndent added in v2.1.22

func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)

MarshalIndent

@param indent 为了兼容性,用" "(4个空格)替代"\t"

func MarshalIndentToString added in v2.1.22

func MarshalIndentToString(v interface{}, prefix, indent string) (string, error)

MarshalIndentToString

@param indent 为了兼容性,用" "(4个空格)替代"\t"

func MarshalIndentToStringWithAPI added in v2.1.40

func MarshalIndentToStringWithAPI(api API, v interface{}, prefix, indent string) (string, error)

MarshalIndentToStringWithAPI

@param indent 为了兼容性,用" "(4个空格)替代"\t"

func MarshalIndentWithAPI added in v2.1.40

func MarshalIndentWithAPI(api API, v interface{}, prefix, indent string) ([]byte, error)

MarshalIndentWithAPI

@param indent 为了兼容性,用" "(4个空格)替代"\t"

func MarshalToFile added in v2.2.3

func MarshalToFile(in interface{}, filePath string, perm os.FileMode) error

MarshalToFile

PS: (1) 对 传参filePath 的验证和断言在 fileKit.WriteToFile 里面; (2) 写入文件的json带有 indent.

@param in 建议为结构体实例指针 || map实例 || slice实例 @param filePath (1) .json 格式的文件

(2) 不存在的话,会创建一个新的文件
(3) 存在且是个文件的话,会 "覆盖" 掉旧的(并不会加到该文件的最后面)

func MarshalToFileWithAPI added in v2.2.3

func MarshalToFileWithAPI(api API, in interface{}, filePath string, perm os.FileMode) error

MarshalToFileWithAPI

PS: (1) 对 传参filePath 的验证和断言在 fileKit.WriteToFile 里面; (2) 写入文件的json带有 indent.

@param in 建议为结构体实例指针 || map实例 || slice实例 @param filePath (1) .json 格式的文件

(2) 不存在的话,会创建一个新的文件
(3) 存在且是个文件的话,会 "覆盖" 掉旧的(并不会加到该文件的最后面)

func MarshalToString

func MarshalToString(v interface{}) (string, error)

MarshalToString

e.g.

fmt.Println(jsonKit.MarshalToString(nil)) // null <nil>

func MarshalToStringWithAPI added in v2.1.40

func MarshalToStringWithAPI(api API, v interface{}) (string, error)

func MarshalWithAPI added in v2.1.40

func MarshalWithAPI(api API, v interface{}) ([]byte, error)

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal 反序列化

@param v (1) 必须是指针(结构体实例指针 || map实例指针 || slice实例指针);

(2) 如果为 slice 或 map 类型,值可以为nil.

func UnmarshalFromString

func UnmarshalFromString(str string, v interface{}) error

func UnmarshalFromStringWithAPI added in v2.1.40

func UnmarshalFromStringWithAPI(api API, str string, v interface{}) error

func UnmarshalWithAPI added in v2.1.40

func UnmarshalWithAPI(api API, data []byte, v interface{}) error

Types

type API added in v2.1.22

type API interface {
	Marshal(v interface{}) ([]byte, error)

	MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)

	MarshalToString(v interface{}) (string, error)

	Unmarshal(data []byte, v interface{}) error

	UnmarshalFromString(str string, v interface{}) error
}

func GetDefaultApi added in v2.1.55

func GetDefaultApi() API

func GetStdApi added in v2.1.55

func GetStdApi() API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL