gJSON

package module
v0.0.0-...-021cb4c Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

README

gJSON

gJSON是方便解析和生成json数据的golang包

使用示例

obj0 := gJSON.ParseObject(`{"k0":"string","k1":true,"k2":false,"k3":null,"k4":123,"k5":1.1314,"k6":{},"k7":[]}`)
log.Println(obj0.AsString())
log.Println(obj0.GetString("k0"))
log.Println(obj0.GetBool("k1"))
log.Println(obj0.GetBool("k2"))
log.Println(obj0.GetString("k3"))
log.Println(obj0.GetInt("k4"))
log.Println(obj0.GetDouble("k5"))
log.Println(obj0.GetObject("k6").AsString())
log.Println(obj0.GetArray("k7").AsString())
arr0 := gJSON.ParseArray(`["string",true,false,null,123,1.1314,{},[]]`)
log.Println(arr0.AsString())
log.Println(arr0.GetString(0))
log.Println(arr0.GetBool(1))
log.Println(arr0.GetBool(2))
log.Println(arr0.GetString(3))
log.Println(arr0.GetInt(4))
log.Println(arr0.GetDouble(5))
log.Println(arr0.GetObject(6).AsString())
log.Println(arr0.GetArray(7).AsString())
obj0 := gJSON.NewObject()
obj0.SetString(`k0`, `string`)
obj0.SetBool(`k1`, true)
obj0.SetBool(`k2`, false)
obj0.SetNull(`k3`)
obj0.SetInt(`k4`, 123)
obj0.SetDouble(`k5`, 1.1314)
obj1 := gJSON.NewObject()
obj0.SetObject(`k6`, obj1)
arr1 := gJSON.NewArray()
obj0.SetArray(`k7`, arr1)
obj1.SetNull(`k00`)
arr1.AddBool(true)
log.Println(obj0.AsString())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringTrim

func StringTrim(str string) string

Types

type JSONNumber

type JSONNumber struct {
	// contains filtered or unexported fields
}

type JSONString

type JSONString []rune

type JsonArray

type JsonArray struct {
	// contains filtered or unexported fields
}

func NewArray

func NewArray() (arr *JsonArray)

func ParseArray

func ParseArray(s string) (arr *JsonArray)

func (*JsonArray) A

func (a *JsonArray) A(idx int) *JsonArray

func (*JsonArray) Add

func (a *JsonArray) Add(v interface{}) int

func (*JsonArray) AddArray

func (a *JsonArray) AddArray(v *JsonArray) int

func (*JsonArray) AddBool

func (a *JsonArray) AddBool(v bool) int

func (*JsonArray) AddDouble

func (a *JsonArray) AddDouble(v float64) int

func (*JsonArray) AddFloat

func (a *JsonArray) AddFloat(v float32) int

func (*JsonArray) AddInt

func (a *JsonArray) AddInt(v int) int

func (*JsonArray) AddInt32

func (a *JsonArray) AddInt32(v int32) int

func (*JsonArray) AddInt64

func (a *JsonArray) AddInt64(v int64) int

func (*JsonArray) AddNull

func (a *JsonArray) AddNull() int

func (*JsonArray) AddObject

func (a *JsonArray) AddObject(v *JsonObject) int

func (*JsonArray) AddString

func (a *JsonArray) AddString(v string) int

func (*JsonArray) AsJson

func (a *JsonArray) AsJson() (str string)

func (*JsonArray) AsString

func (a *JsonArray) AsString() (str string)

func (*JsonArray) B

func (a *JsonArray) B(idx int) interface{}

func (*JsonArray) D

func (a *JsonArray) D(idx int) float64

func (*JsonArray) F

func (a *JsonArray) F(idx int) float32

func (*JsonArray) GetArray

func (a *JsonArray) GetArray(idx int) *JsonArray

func (*JsonArray) GetBool

func (a *JsonArray) GetBool(idx int) bool

func (*JsonArray) GetDouble

func (a *JsonArray) GetDouble(idx int) float64

func (*JsonArray) GetFloat

func (a *JsonArray) GetFloat(idx int) float32

func (*JsonArray) GetInt

func (a *JsonArray) GetInt(idx int) int

func (*JsonArray) GetInt32

func (a *JsonArray) GetInt32(idx int) int32

func (*JsonArray) GetInt64

func (a *JsonArray) GetInt64(idx int) int64

func (*JsonArray) GetObject

func (a *JsonArray) GetObject(idx int) *JsonObject

func (*JsonArray) GetString

func (a *JsonArray) GetString(idx int) string

func (*JsonArray) I

func (a *JsonArray) I(idx int) int

func (*JsonArray) I32

func (a *JsonArray) I32(idx int) int32

func (*JsonArray) I64

func (a *JsonArray) I64(idx int) int64

func (*JsonArray) O

func (a *JsonArray) O(idx int) *JsonObject

func (*JsonArray) Remove

func (a *JsonArray) Remove(idx int) bool

func (*JsonArray) S

func (a *JsonArray) S(idx int) string

func (*JsonArray) SetArray

func (a *JsonArray) SetArray(idx int, arr *JsonArray)

func (*JsonArray) SetBool

func (a *JsonArray) SetBool(idx int, b bool)

func (*JsonArray) SetDouble

func (a *JsonArray) SetDouble(idx int, f64 float64)

func (*JsonArray) SetFloat

func (a *JsonArray) SetFloat(idx int, f32 float32)

func (*JsonArray) SetInt

func (a *JsonArray) SetInt(idx int, i int)

func (*JsonArray) SetInt32

func (a *JsonArray) SetInt32(idx int, i32 int32)

func (*JsonArray) SetInt64

func (a *JsonArray) SetInt64(idx int, i64 int64)

func (*JsonArray) SetNull

func (a *JsonArray) SetNull(idx int)

func (*JsonArray) SetObject

func (a *JsonArray) SetObject(idx int, obj *JsonObject)

func (*JsonArray) SetString

func (a *JsonArray) SetString(idx int, s string)

func (*JsonArray) Val

func (a *JsonArray) Val(idx int) (val *JsonValue)

func (*JsonArray) Values

func (a *JsonArray) Values() []*JsonValue

type JsonElement

type JsonElement struct {
	// contains filtered or unexported fields
}

type JsonNode

type JsonNode struct {
	// contains filtered or unexported fields
}

func LoadFromFile

func LoadFromFile(fname string) (node *JsonNode, err error)

func New

func New(ss ...string) *JsonNode

New JSONNode //////////////////////////////////////////////////////////////////////////////////////////////////

func (*JsonNode) AsArray

func (this *JsonNode) AsArray() *JsonArray

func (*JsonNode) AsObject

func (this *JsonNode) AsObject() *JsonObject

func (*JsonNode) AsString

func (this *JsonNode) AsString() string

func (*JsonNode) IsArray

func (this *JsonNode) IsArray() bool

func (*JsonNode) IsObject

func (this *JsonNode) IsObject() bool

func (*JsonNode) Val

func (this *JsonNode) Val(k interface{}) *JsonValue

type JsonObject

type JsonObject struct {
	// contains filtered or unexported fields
}

func NewObject

func NewObject() (obj *JsonObject)

NewObject JsonObject //////////////////////////////////////////////////////////////////////////////////////////////////

func ParseObject

func ParseObject(s string) (obj *JsonObject)

func (*JsonObject) AsJson

func (O *JsonObject) AsJson() (str string)

func (*JsonObject) AsString

func (O *JsonObject) AsString() (str string)

func (*JsonObject) Contains

func (O *JsonObject) Contains(k string) bool

func (*JsonObject) GetArray

func (O *JsonObject) GetArray(k string) *JsonArray

func (*JsonObject) GetBool

func (O *JsonObject) GetBool(k string) bool

func (*JsonObject) GetDouble

func (O *JsonObject) GetDouble(k string) float64

func (*JsonObject) GetFloat

func (O *JsonObject) GetFloat(k string) float32

func (*JsonObject) GetInt

func (O *JsonObject) GetInt(k string) int

func (*JsonObject) GetInt32

func (O *JsonObject) GetInt32(k string) int32

func (*JsonObject) GetInt64

func (O *JsonObject) GetInt64(k string) int64

func (*JsonObject) GetNames

func (O *JsonObject) GetNames() (arr *JsonArray)

func (*JsonObject) GetObject

func (O *JsonObject) GetObject(k string) *JsonObject

func (*JsonObject) GetString

func (O *JsonObject) GetString(k string) string

func (*JsonObject) GetValues

func (O *JsonObject) GetValues() (arr *JsonArray)

func (*JsonObject) Has

func (O *JsonObject) Has(k string) bool

func (*JsonObject) KeyAsArray

func (O *JsonObject) KeyAsArray(k string) *JsonArray

func (*JsonObject) KeyAsDouble

func (O *JsonObject) KeyAsDouble(k string) float64

func (*JsonObject) KeyAsFloat

func (O *JsonObject) KeyAsFloat(k string) float32

func (*JsonObject) KeyAsInt

func (O *JsonObject) KeyAsInt(k string) int

func (*JsonObject) KeyAsInt32

func (O *JsonObject) KeyAsInt32(k string) int32

func (*JsonObject) KeyAsInt64

func (O *JsonObject) KeyAsInt64(k string) int64

func (*JsonObject) KeyAsObject

func (O *JsonObject) KeyAsObject(k string) *JsonObject

func (*JsonObject) KeyAsString

func (O *JsonObject) KeyAsString(k string) string

func (*JsonObject) Remove

func (O *JsonObject) Remove(k string) bool

func (*JsonObject) Set

func (O *JsonObject) Set(k string, v interface{})

func (*JsonObject) SetArray

func (O *JsonObject) SetArray(k string, v *JsonArray)

func (*JsonObject) SetBool

func (O *JsonObject) SetBool(k string, v bool)

func (*JsonObject) SetDouble

func (O *JsonObject) SetDouble(k string, v float64)

func (*JsonObject) SetFloat

func (O *JsonObject) SetFloat(k string, v float32)

func (*JsonObject) SetInt

func (O *JsonObject) SetInt(k string, v int)

func (*JsonObject) SetInt32

func (O *JsonObject) SetInt32(k string, v int32)

func (*JsonObject) SetInt64

func (O *JsonObject) SetInt64(k string, v int64)

func (*JsonObject) SetNull

func (O *JsonObject) SetNull(k string)

func (*JsonObject) SetObject

func (O *JsonObject) SetObject(k string, v *JsonObject)

func (*JsonObject) SetString

func (O *JsonObject) SetString(k, v string)

func (*JsonObject) Val

func (O *JsonObject) Val(k string) (val *JsonValue)

func (*JsonObject) ValErr

func (O *JsonObject) ValErr(k string) (val *JsonValue, err error)

type JsonTokenizer

type JsonTokenizer struct {
	// contains filtered or unexported fields
}

type JsonValue

type JsonValue struct {
	// contains filtered or unexported fields
}

func (*JsonValue) AsArray

func (v *JsonValue) AsArray() (arr *JsonArray, err error)

func (*JsonValue) AsBool

func (v *JsonValue) AsBool() (bool, error)

func (*JsonValue) AsBoolDef

func (v *JsonValue) AsBoolDef(def bool) bool

func (*JsonValue) AsDouble

func (v *JsonValue) AsDouble() (float64, error)

func (*JsonValue) AsDoubleDef

func (v *JsonValue) AsDoubleDef(def float64) (val float64)

func (*JsonValue) AsFloat32

func (v *JsonValue) AsFloat32() (val float32, err error)

func (*JsonValue) AsFloat32Def

func (v *JsonValue) AsFloat32Def(def float32) (val float32)

func (*JsonValue) AsFloat64

func (v *JsonValue) AsFloat64() (val float64, err error)

func (*JsonValue) AsFloat64Def

func (v *JsonValue) AsFloat64Def(def float64) (val float64)

func (*JsonValue) AsInt

func (v *JsonValue) AsInt() (int, error)

func (*JsonValue) AsInt32

func (v *JsonValue) AsInt32() (int32, error)

func (*JsonValue) AsInt32Def

func (v *JsonValue) AsInt32Def(def int32) (val int32)

func (*JsonValue) AsInt64

func (v *JsonValue) AsInt64() (val int64, err error)

func (*JsonValue) AsInt64Def

func (v *JsonValue) AsInt64Def(def int64) (val int64)

func (*JsonValue) AsIntDef

func (v *JsonValue) AsIntDef(def int) (val int)

func (*JsonValue) AsObject

func (v *JsonValue) AsObject() (obj *JsonObject, err error)

func (*JsonValue) AsString

func (v *JsonValue) AsString() (str string, err error)

func (*JsonValue) AsStringDef

func (v *JsonValue) AsStringDef(def string) (val string)

func (*JsonValue) IsArray

func (v *JsonValue) IsArray() bool

func (*JsonValue) IsBool

func (v *JsonValue) IsBool() bool

func (*JsonValue) IsFalse

func (v *JsonValue) IsFalse() bool

func (*JsonValue) IsNull

func (v *JsonValue) IsNull() bool

func (*JsonValue) IsNumber

func (v *JsonValue) IsNumber() bool

func (*JsonValue) IsObject

func (v *JsonValue) IsObject() bool

func (*JsonValue) IsString

func (v *JsonValue) IsString() bool

func (*JsonValue) IsTrue

func (v *JsonValue) IsTrue() bool

type ValType

type ValType int

Jump to

Keyboard shortcuts

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