json

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

README

json

json包是为了方便对json格式的字符处理使用

{
    "k1":12,
    "k2":true,
    "k3":{
        "k31":32,
        "k32":"str",
        "k33":{
            "k331":12
        }
    }
}
func TestLoad(t *testing.T) {
    jsonObject := json.Object{}
    // str就是上面的字符串
    err := jsonObject.Load(str)
    if err != nil {
        fmt.Println(err.Error())
        return
    }

    assert.Equal(t, jsonObject.Get("k1"), 12)
    assert.Equal(t, jsonObject.Get("k2"), true)
    // 支持连key获取
    assert.Equal(t, jsonObject.Get("k3.k31"), 32)
    assert.Equal(t, jsonObject.Get("k3.k32"), "str")
    assert.Equal(t, jsonObject.Get("k3.k33.k331"), 12)
}

另外也提供了各种类型的api用于指定的类型使用


GetString(key string) string
GetInt(key string) int
GetInt8(key string) int8
GetInt16(key string) int16
GetInt32(key string) int32
GetInt64(key string) int64
GetUInt(key string) uint
GetUInt8(key string) uint8
GetUInt16(key string) uint16
GetUInt32(key string) uint32
GetUInt64(key string) uint64
GetFloat32(key string) float32
GetFloat64(key string) float64
GetBool(key string) bool
GetObject(key string, targetPtrObj any) error
GetArray(key string) []any

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Object

type Object struct {
	ValueMap     map[string]any
	ValueDeepMap map[string]any
}

func (*Object) Get

func (jsonObject *Object) Get(key string) any

func (*Object) GetArray

func (jsonObject *Object) GetArray(key string) []any

func (*Object) GetBool

func (jsonObject *Object) GetBool(key string) bool

func (*Object) GetFloat32

func (jsonObject *Object) GetFloat32(key string) float32

func (*Object) GetFloat64

func (jsonObject *Object) GetFloat64(key string) float64

func (*Object) GetInt

func (jsonObject *Object) GetInt(key string) int

func (*Object) GetInt16

func (jsonObject *Object) GetInt16(key string) int16

func (*Object) GetInt32

func (jsonObject *Object) GetInt32(key string) int32

func (*Object) GetInt64

func (jsonObject *Object) GetInt64(key string) int64

func (*Object) GetInt8

func (jsonObject *Object) GetInt8(key string) int8

func (*Object) GetObject

func (jsonObject *Object) GetObject(key string, targetPtrObj any) error

func (*Object) GetString

func (jsonObject *Object) GetString(key string) string

func (*Object) GetUInt

func (jsonObject *Object) GetUInt(key string) uint

func (*Object) GetUInt16

func (jsonObject *Object) GetUInt16(key string) uint16

func (*Object) GetUInt32

func (jsonObject *Object) GetUInt32(key string) uint32

func (*Object) GetUInt64

func (jsonObject *Object) GetUInt64(key string) uint64

func (*Object) GetUInt8

func (jsonObject *Object) GetUInt8(key string) uint8

func (*Object) Load

func (jsonObject *Object) Load(jsonContent string) error

func (*Object) Put

func (jsonObject *Object) Put(key string, value any)

Jump to

Keyboard shortcuts

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