sdjson

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sdjson JSON工具库

Index

Constants

This section is empty.

Variables

View Source
var (
	Unmarshal     = json.Unmarshal
	Marshal       = json.Marshal
	MarshalIndent = json.MarshalIndent
)

Functions

func As

func As[T any](v any) (T, bool)

func AsBool

func AsBool(v any) (bool, bool)

func AsBoolDef

func AsBoolDef(v any, def bool) bool

func AsDef

func AsDef[T any](v any, def T) T

func AsFloat

func AsFloat[T float32 | float64](v any) (T, bool)

func AsFloatDef

func AsFloatDef[T float32 | float64](v any, def T) T

func AsInt

func AsInt[T int | int8 | int16 | int32 | int64](v any) (T, bool)

func AsIntDef

func AsIntDef[T int | int8 | int16 | int32 | int64](v any, def T) T

func AsString

func AsString(v any) (string, bool)

func AsStringDef

func AsStringDef(v any, def string) string

func AsUint

func AsUint[T uint | uint8 | uint16 | uint32 | uint64](v any) (T, bool)

func AsUintDef

func AsUintDef[T uint | uint8 | uint16 | uint32 | uint64](v any, def T) T

func MarshalBase64

func MarshalBase64(v any) (string, error)

func MarshalBase64Def

func MarshalBase64Def(v any, def string) string

func MarshalIndentString

func MarshalIndentString(v any, prefix, indent string) (string, error)

func MarshalIndentStringDef

func MarshalIndentStringDef(v any, prefix, indent, def string) string

func MarshalPretty

func MarshalPretty(v any) string

func MarshalString

func MarshalString(v any) (string, error)

func MarshalStringDef

func MarshalStringDef(v any, def string) string

func ObjectToStruct

func ObjectToStruct[T any](o Object) (T, error)

func Register

func Register(c Converter)

func To

func To[T any](v any) (T, bool)

func ToBool

func ToBool(v any) (bool, bool)

func ToFloat

func ToFloat[T float32 | float64](v any) (T, bool)

func ToInt

func ToInt[T int | int8 | int16 | int32 | int64](v any) (T, bool)

func ToPrimitive

func ToPrimitive(v any) (any, error)

func ToPrimitiveDef

func ToPrimitiveDef(v any, def any) any

func ToString

func ToString(v any) (string, bool)

func ToUint

func ToUint[T uint | uint8 | uint16 | uint32 | uint64](v any) (T, bool)

func TryPrimitive

func TryPrimitive(v any) any

func UnmarshalBase64

func UnmarshalBase64(b64 string, v any) error

func UnmarshalBase64Typed

func UnmarshalBase64Typed[T any](b64 string) (T, error)

func UnmarshalBase64TypedDef

func UnmarshalBase64TypedDef[T any](b64 string, def T) T

func UnmarshalString

func UnmarshalString(s string, v any) error

func UnmarshalStringTyped

func UnmarshalStringTyped[T any](j string) (T, error)

func UnmarshalStringTypedDef

func UnmarshalStringTypedDef[T any](j string, def T) T

func UnmarshalTyped

func UnmarshalTyped[T any](raw []byte) (T, error)

func UnmarshalTypedDef

func UnmarshalTypedDef[T any](raw []byte, def T) T

Types

type Array

type Array []any

func AsArray

func AsArray(v any) (Array, bool)

func AsArrayDef

func AsArrayDef(v any, def Array) Array

func ToArray

func ToArray(v any) (Array, bool)

func (Array) At

func (a Array) At(i int) Value

func (Array) Has

func (a Array) Has(i int) bool

func (Array) Len

func (a Array) Len() int

func (Array) ShadowCopy

func (a Array) ShadowCopy() Array

type Converter

type Converter interface {
	ToBool(v any, as bool) (bool, bool)
	ToString(v any, as bool) (string, bool)
	ToInt(v any, as bool) (int64, bool)
	ToUint(v any, as bool) (uint64, bool)
	ToFloat(v any, as bool) (float64, bool)
	ToObject(v any, as bool) (Object, bool)
	ToArray(v any, as bool) (Array, bool)
	ToAny(v any, as bool, ptr any) bool
}

type Object

type Object map[string]any

func AsObject

func AsObject(v any) (Object, bool)

func AsObjectDef

func AsObjectDef(v any, def Object) Object

func StructToObject

func StructToObject(v any) (Object, error)

func ToObject

func ToObject(v any) (Object, bool)

func (Object) Get

func (o Object) Get(k string) Value

func (Object) Has

func (o Object) Has(k string) bool

func (Object) Len

func (o Object) Len() int

func (Object) Set

func (o Object) Set(k string, v any) Object

func (Object) ShadowCopy

func (o Object) ShadowCopy() Object

func (Object) TryGet

func (o Object) TryGet(keys ...string) Value

func (Object) TryPrimitive

func (o Object) TryPrimitive() Object

type Value

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

func UnmarshalValue

func UnmarshalValue(raw []byte) (Value, error)

func UnmarshalValueString

func UnmarshalValueString(s string) (Value, error)

func V

func V(v any) Value

func (Value) As

func (v Value) As(ptr any) bool

func (Value) AsArray

func (v Value) AsArray() (Array, bool)

func (Value) AsArrayDef

func (v Value) AsArrayDef(def Array) Array

func (Value) AsBool

func (v Value) AsBool() (bool, bool)

func (Value) AsBoolDef

func (v Value) AsBoolDef(def bool) bool

func (Value) AsFloat32

func (v Value) AsFloat32() (float32, bool)

func (Value) AsFloat32Def

func (v Value) AsFloat32Def(def float32) float32

func (Value) AsFloat64

func (v Value) AsFloat64() (float64, bool)

func (Value) AsFloat64Def

func (v Value) AsFloat64Def(def float64) float64

func (Value) AsInt

func (v Value) AsInt() (int, bool)

func (Value) AsInt16

func (v Value) AsInt16() (int16, bool)

func (Value) AsInt16Def

func (v Value) AsInt16Def(def int16) int16

func (Value) AsInt32

func (v Value) AsInt32() (int32, bool)

func (Value) AsInt32Def

func (v Value) AsInt32Def(def int32) int32

func (Value) AsInt64

func (v Value) AsInt64() (int64, bool)

func (Value) AsInt64Def

func (v Value) AsInt64Def(def int64) int64

func (Value) AsInt8

func (v Value) AsInt8() (int8, bool)

func (Value) AsInt8Def

func (v Value) AsInt8Def(def int8) int8

func (Value) AsIntDef

func (v Value) AsIntDef(def int) int

func (Value) AsObject

func (v Value) AsObject() (Object, bool)

func (Value) AsObjectDef

func (v Value) AsObjectDef(def Object) Object

func (Value) AsString

func (v Value) AsString() (string, bool)

func (Value) AsStringDef

func (v Value) AsStringDef(def string) string

func (Value) AsUint

func (v Value) AsUint() (uint, bool)

func (Value) AsUint16

func (v Value) AsUint16() (uint16, bool)

func (Value) AsUint16Def

func (v Value) AsUint16Def(def uint16) uint16

func (Value) AsUint32

func (v Value) AsUint32() (uint32, bool)

func (Value) AsUint32Def

func (v Value) AsUint32Def(def uint32) uint32

func (Value) AsUint64

func (v Value) AsUint64() (uint64, bool)

func (Value) AsUint64Def

func (v Value) AsUint64Def(def uint64) uint64

func (Value) AsUint8

func (v Value) AsUint8() (uint8, bool)

func (Value) AsUint8Def

func (v Value) AsUint8Def(def uint8) uint8

func (Value) AsUintDef

func (v Value) AsUintDef(def uint) uint

func (Value) At

func (v Value) At(i int) Value

func (Value) Get

func (v Value) Get(k string) Value

func (Value) Gets

func (v Value) Gets(k string, subKeys ...string) Value

func (Value) Interface

func (v Value) Interface() any

func (Value) IsNil

func (v Value) IsNil() bool

func (Value) MarshalJSON

func (v Value) MarshalJSON() ([]byte, error)

func (Value) To

func (v Value) To(ptr any) bool

func (Value) ToArray

func (v Value) ToArray() (Array, bool)

func (Value) ToBool

func (v Value) ToBool() (bool, bool)

func (Value) ToFloat32

func (v Value) ToFloat32() (float32, bool)

func (Value) ToFloat64

func (v Value) ToFloat64() (float64, bool)

func (Value) ToInt

func (v Value) ToInt() (int, bool)

func (Value) ToInt16

func (v Value) ToInt16() (int16, bool)

func (Value) ToInt32

func (v Value) ToInt32() (int32, bool)

func (Value) ToInt64

func (v Value) ToInt64() (int64, bool)

func (Value) ToInt8

func (v Value) ToInt8() (int8, bool)

func (Value) ToObject

func (v Value) ToObject() (Object, bool)

func (Value) ToString

func (v Value) ToString() (string, bool)

func (Value) ToUint

func (v Value) ToUint() (uint, bool)

func (Value) ToUint16

func (v Value) ToUint16() (uint16, bool)

func (Value) ToUint32

func (v Value) ToUint32() (uint32, bool)

func (Value) ToUint64

func (v Value) ToUint64() (uint64, bool)

func (Value) ToUint8

func (v Value) ToUint8() (uint8, bool)

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(raw []byte) error

Jump to

Keyboard shortcuts

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