// 概述
// 包jsoniter实现RFC4627中定义的JSON编码和解码,并提供与标准lib encoding/JSON语法相同的接口。从encoding/json到jsoniter的转换无非是用jsoniter和变量类型声明(如果有的话)替换包。jsoniter接口与使用标准库的代码具有100%的兼容性。
// “JSON和Go”(https://golang.org/doc/articles/json_and_go.html)描述封送/解组如何在任意或预定义的json对象和字节之间进行操作,它也适用于jsoniter.Marshal/Unmarshal。
// 此外,jsoniter.Iterator提供了一组不同的接口,迭代给定的字节/字符串/读取器,并逐个生成解析的元素。这组接口根据需要读取输入并提供更好的性能。
func CastJsonNumber(val interface{}) (string, bool)
func Marshal(v interface{}) ([]byte, error)
func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)
func MarshalToString(v interface{}) (string, error)
func RegisterExtension(extension Extension)
func RegisterFieldDecoder(typ string, field string, decoder ValDecoder)
func RegisterFieldDecoderFunc(typ string, field string, fun DecoderFunc)
func RegisterFieldEncoder(typ string, field string, encoder ValEncoder)
func RegisterFieldEncoderFunc(typ string, field string, fun EncoderFunc, ...)
func RegisterTypeDecoder(typ string, decoder ValDecoder)
func RegisterTypeDecoderFunc(typ string, fun DecoderFunc)
func RegisterTypeEncoder(typ string, encoder ValEncoder)
func RegisterTypeEncoderFunc(typ string, fun EncoderFunc, isEmptyFunc func(unsafe.Pointer) bool)
func Unmarshal(data []byte, v interface{}) error
func UnmarshalFromString(str string, v interface{}) error
func Valid(data []byte) bool
type API
type Any
func Get(data []byte, path ...interface{}) Any
func Wrap(val interface{}) Any
func WrapFloat64(val float64) Any
func WrapInt32(val int32) Any
func WrapInt64(val int64) Any
func WrapString(val string) Any
func WrapUint32(val uint32) Any
func WrapUint64(val uint64) Any
type Binding
type Config
func (cfg Config) Froze() API
type Decoder
func NewDecoder(reader io.Reader) *Decoder
func (adapter *Decoder) Buffered() io.Reader
func (adapter *Decoder) Decode(obj interface{}) error
func (adapter *Decoder) DisallowUnknownFields()
func (adapter *Decoder) More() bool
func (adapter *Decoder) UseNumber()
type DecoderExtension
func (extension DecoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder
func (extension DecoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder
func (extension DecoderExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder
func (extension DecoderExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder
func (extension DecoderExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder
func (extension DecoderExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder
func (extension DecoderExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor)
type DecoderFunc
type DummyExtension
func (extension *DummyExtension) CreateDecoder(typ reflect2.Type) ValDecoder
func (extension *DummyExtension) CreateEncoder(typ reflect2.Type) ValEncoder
func (extension *DummyExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder
func (extension *DummyExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder
func (extension *DummyExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder
func (extension *DummyExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder
func (extension *DummyExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor)
type Encoder
func NewEncoder(writer io.Writer) *Encoder
func (adapter *Encoder) Encode(val interface{}) error
func (adapter *Encoder) SetEscapeHTML(escapeHTML bool)
func (adapter *Encoder) SetIndent(prefix, indent string)
type EncoderExtension
func (extension EncoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder
func (extension EncoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder
func (extension EncoderExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder
func (extension EncoderExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder
func (extension EncoderExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder
func (extension EncoderExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder
func (extension EncoderExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor)
type EncoderFunc
type Extension
type IsEmbeddedPtrNil
type Iterator
func NewIterator(cfg API) *Iterator
func Parse(cfg API, reader io.Reader, bufSize int) *Iterator
func ParseBytes(cfg API, input []byte) *Iterator
func ParseString(cfg API, input string) *Iterator
func (iter *Iterator) CurrentBuffer() string
func (iter *Iterator) Pool() IteratorPool
func (iter *Iterator) Read() interface{}
func (iter *Iterator) ReadAny() Any
func (iter *Iterator) ReadArray() (ret bool)
func (iter *Iterator) ReadArrayCB(callback func(*Iterator) bool) (ret bool)
func (iter *Iterator) ReadBigFloat() (ret *big.Float)
func (iter *Iterator) ReadBigInt() (ret *big.Int)
func (iter *Iterator) ReadBool() (ret bool)
func (iter *Iterator) ReadFloat32() (ret float32)
func (iter *Iterator) ReadFloat64() (ret float64)
func (iter *Iterator) ReadInt() int
func (iter *Iterator) ReadInt16() (ret int16)
func (iter *Iterator) ReadInt32() (ret int32)
func (iter *Iterator) ReadInt64() (ret int64)
func (iter *Iterator) ReadInt8() (ret int8)
func (iter *Iterator) ReadMapCB(callback func(*Iterator, string) bool) bool
func (iter *Iterator) ReadNil() (ret bool)
func (iter *Iterator) ReadNumber() (ret json.Number)
func (iter *Iterator) ReadObject() (ret string)
func (iter *Iterator) ReadObjectCB(callback func(*Iterator, string) bool) bool
func (iter *Iterator) ReadString() (ret string)
func (iter *Iterator) ReadStringAsSlice() (ret []byte)
func (iter *Iterator) ReadUint() uint
func (iter *Iterator) ReadUint16() (ret uint16)
func (iter *Iterator) ReadUint32() (ret uint32)
func (iter *Iterator) ReadUint64() uint64
func (iter *Iterator) ReadUint8() (ret uint8)
func (iter *Iterator) ReadVal(obj interface{})
func (iter *Iterator) ReportError(operation string, msg string)
func (iter *Iterator) Reset(reader io.Reader) *Iterator
func (iter *Iterator) ResetBytes(input []byte) *Iterator
func (iter *Iterator) Skip()
func (iter *Iterator) SkipAndAppendBytes(buf []byte) []byte
func (iter *Iterator) SkipAndReturnBytes() []byte
func (iter *Iterator) WhatIsNext() ValueType
type IteratorPool
type Number
func (n Number) Float64() (float64, error)
func (n Number) Int64() (int64, error)
func (n Number) String() string
type OptionalDecoder
func (decoder *OptionalDecoder) Decode(ptr unsafe.Pointer, iter *Iterator)
type OptionalEncoder
func (encoder *OptionalEncoder) Encode(ptr unsafe.Pointer, stream *Stream)
func (encoder *OptionalEncoder) IsEmpty(ptr unsafe.Pointer) bool
type RawMessage
type Stream
func NewStream(cfg API, out io.Writer, bufSize int) *Stream
func (stream *Stream) Available() int
func (stream *Stream) Buffer() []byte
func (stream *Stream) Buffered() int
func (stream *Stream) Flush() error
func (stream *Stream) Pool() StreamPool
func (stream *Stream) Reset(out io.Writer)
func (stream *Stream) SetBuffer(buf []byte)
func (stream *Stream) Write(p []byte) (nn int, err error)
func (stream *Stream) WriteArrayEnd()
func (stream *Stream) WriteArrayStart()
func (stream *Stream) WriteBool(val bool)
func (stream *Stream) WriteEmptyArray()
func (stream *Stream) WriteEmptyObject()
func (stream *Stream) WriteFalse()
func (stream *Stream) WriteFloat32(val float32)
func (stream *Stream) WriteFloat32Lossy(val float32)
func (stream *Stream) WriteFloat64(val float64)
func (stream *Stream) WriteFloat64Lossy(val float64)
func (stream *Stream) WriteInt(val int)
func (stream *Stream) WriteInt16(nval int16)
func (stream *Stream) WriteInt32(nval int32)
func (stream *Stream) WriteInt64(nval int64)
func (stream *Stream) WriteInt8(nval int8)
func (stream *Stream) WriteMore()
func (stream *Stream) WriteNil()
func (stream *Stream) WriteObjectEnd()
func (stream *Stream) WriteObjectField(field string)
func (stream *Stream) WriteObjectStart()
func (stream *Stream) WriteRaw(s string)
func (stream *Stream) WriteString(s string)
func (stream *Stream) WriteStringWithHTMLEscaped(s string)
func (stream *Stream) WriteTrue()
func (stream *Stream) WriteUint(val uint)
func (stream *Stream) WriteUint16(val uint16)
func (stream *Stream) WriteUint32(val uint32)
func (stream *Stream) WriteUint64(val uint64)
func (stream *Stream) WriteUint8(val uint8)
func (stream *Stream) WriteVal(val interface{})
type StreamPool
type StructDescriptor
func (structDescriptor *StructDescriptor) GetField(fieldName string) *Binding
type ValDecoder
type ValEncoder
type ValueType
var ConfigCompatibleWithStandardLibrary = Config{
EscapeHTML: true,
SortMapKeys: true,
ValidateJsonRawMessage: true,
}.Froze()
// ConfigCompatibleWithStandardLibrary尝试与标准库行为100%兼容
var ConfigDefault = Config{
EscapeHTML: true,
}.Froze()
// ConfigDefault是默认的API
var ConfigFastest = Config{
EscapeHTML: false,
MarshalFloatWith6Digits: true,
ObjectFieldMustBeSimpleString: true,
}.Froze()
// 配置最快的封送处理浮点,精度仅为6位
// 功能
func CastJsonNumber
func CastJsonNumber(val interface{}) (string, bool)
func Marshal
func Marshal(v interface{}) ([]byte, error)
// 封送处理适应json/编码封送处理API
// Marshal返回v的JSON编码,适应JSON/编码Marshal API参考https://godoc.org/encoding/json#Marshal 更多信息
// 实例
type ColorGroup struct {
ID int
Name string
Colors []string
}
group := ColorGroup{
ID: 1,
Name: "Reds",
Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
}
b, err := Marshal(group)
if err != nil {
fmt.Println("error:", err)
}
os.Stdout.Write(b)
Output:
{"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]}
func MarshalIndent
func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)
// MarshalIndent与json.MarshalIndent相同。不支持前缀。
func MarshalToString
func MarshalToString(v interface{}) (string, error)
// MarshallToString作为字符串而不是[]字节写入的方便方法
func RegisterExtension
func RegisterExtension(extension Extension)
// 寄存器扩展寄存器扩展
func RegisterFieldDecoder
func RegisterFieldDecoder(typ string, field string, decoder ValDecoder)
// 结构字段的RegisterFieldCoder寄存器类型解码器
func RegisterFieldDecoderFunc
func RegisterFieldDecoderFunc(typ string, field string, fun DecoderFunc)
// 带函数的结构字段的RegisterFieldDecoderFunc寄存器类型解码器
func RegisterFieldEncoder
func RegisterFieldEncoder(typ string, field string, encoder ValEncoder)
// 结构字段的RegisterFieldCoder寄存器类型编码器
func RegisterFieldEncoderFunc
func RegisterFieldEncoderFunc(typ string, field string, fun EncoderFunc, isEmptyFunc func(unsafe.Pointer) bool)
// 带有encode/isEmpty函数的结构字段的RegisterFieldEncoderFunc寄存器类型编码器
func RegisterTypeDecoder
func RegisterTypeDecoder(typ string, decoder ValDecoder)
// 寄存器类型解码器用于类型的寄存器类型解码器
func RegisterTypeDecoderFunc
func RegisterTypeDecoderFunc(typ string, fun DecoderFunc)
// 具有函数的类型的RegisterTypeDecoderFunc寄存器TypeDecoder
func RegisterTypeEncoder
func RegisterTypeEncoder(typ string, encoder ValEncoder)
// RegisterTypeEncoder类型的寄存器TypeEncoder
func RegisterTypeEncoderFunc
func RegisterTypeEncoderFunc(typ string, fun EncoderFunc, isEmptyFunc func(unsafe.Pointer) bool)
// 带有encode/isEmpty函数的类型的RegisterTypeEncoderFunc寄存器TypeEncoder
func Unmarshal
func Unmarshal(data []byte, v interface{}) error
// 解组适配json/编码解组API
// Unmarshal解析JSON编码的数据,并将结果存储在v指向的值中。提到 https://godoc.org/encoding/json#Unmarshal 更多信息
// 实例
var jsonBlob = []byte(`[
{"Name": "Platypus", "Order": "Monotremata"},
{"Name": "Quoll", "Order": "Dasyuromorphia"}
]`)
type Animal struct {
Name string
Order string
}
var animals []Animal
err := Unmarshal(jsonBlob, &animals)
if err != nil {
fmt.Println("error:", err)
}
fmt.Printf("%+v", animals)
Output:
[{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}]
func UnmarshalFromString
func UnmarshalFromString(str string, v interface{}) error
// UnmarshalFromString是一种从字符串而不是[]字节读取的方便方法
func Valid
func Valid(data []byte) bool
// Valid报告数据是否为有效的JSON编码。
// 类型
type API
type API interface {
IteratorPool
StreamPool
MarshalToString(v interface{}) (string, error)
Marshal(v interface{}) ([]byte, error)
MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)
UnmarshalFromString(str string, v interface{}) error
Unmarshal(data []byte, v interface{}) error
Get(data []byte, path ...interface{}) Any
NewEncoder(writer io.Writer) *Encoder
NewDecoder(reader io.Reader) *Decoder
Valid(data []byte) bool
RegisterExtension(extension Extension)
DecoderOf(typ reflect2.Type) ValDecoder
EncoderOf(typ reflect2.Type) ValEncoder
}
// API是此包的公共接口。主封送和解封。
type Any
type Any interface {
LastError() error
ValueType() ValueType
MustBeValid() Any
ToBool() bool
ToInt() int
ToInt32() int32
ToInt64() int64
ToUint() uint
ToUint32() uint32
ToUint64() uint64
ToFloat32() float32
ToFloat64() float64
ToString() string
ToVal(val interface{})
Get(path ...interface{}) Any
Size() int
Keys() []string
GetInterface() interface{}
WriteTo(stream *Stream)
}
// 任何通用对象表示。惰性json实现持有[]字节并进行惰性解析。
func Get
func Get(data []byte, path ...interface{}) Any
// Get quick方法从深度嵌套的JSON结构中获取值
// 实例
val := []byte(`{"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]}`)
fmt.Printf(Get(val, "Colors", 0).ToString())
Output:
Crimson
func Wrap
func Wrap(val interface{}) Any
// 将go对象包装到任何接口中
func WrapFloat64
func WrapFloat64(val float64) Any
// WrapFloat64将float64转换为任何接口
func WrapInt32
func WrapInt32(val int32) Any
// WrapInt32将int32转换为任何接口
func WrapInt64
func WrapInt64(val int64) Any
// WrapInt64将int64转换为任何接口
func WrapString
func WrapString(val string) Any
// 包装将字符串转换为任何接口
func WrapUint32
func WrapUint32(val uint32) Any
// WrapUint32将uint32转换为任何接口
func WrapUint64
func WrapUint64(val uint64) Any
// WrapUint64将uint64转换为任何接口
type Binding
type Binding struct {
Field reflect2.StructField
FromNames []string
ToNames []string
Encoder ValEncoder
Decoder ValDecoder
//包含已过滤或未报告的字段
}
// 绑定描述我们应该如何对struct字段进行编码/解码
type Config
type Config struct {
IndentionStep int
MarshalFloatWith6Digits bool
EscapeHTML bool
SortMapKeys bool
UseNumber bool
DisallowUnknownFields bool
TagKey string
OnlyTaggedField bool
ValidateJsonRawMessage bool
ObjectFieldMustBeSimpleString bool
CaseSensitive bool
}
// 配置自定义API的行为方式。API是由Froze从配置创建的。
func (Config) Froze
func (cfg Config) Froze() API
// 从配置中冻结forge API
type Decoder
type Decoder struct {
//包含已过滤或未报告的字段
}
// 解码器从输入流读取并解码JSON值。解码器提供与json/流解码器相同的API(Token()和UseNumber()正在进行中)
func NewDecoder
func NewDecoder(reader io.Reader) *Decoder
// NewDecoder适用于json/stream NewDecoder API。
// NewDecoder返回从r读取的新解码器。
// 不是json/编码解码器,而是返回一个解码器https://godoc.org/encoding/json#NewDecoder 更多信息
func (*Decoder) Buffered
func (adapter *Decoder) Buffered() io.Reader
// 缓冲剩余缓冲区
func (*Decoder) Decode
func (adapter *Decoder) Decode(obj interface{}) error
// 将JSON解码到接口{}
func (*Decoder) DisallowUnknownFields
func (adapter *Decoder) DisallowUnknownFields()
// 当目标为结构且输入包含与目标中任何未忽略的导出字段不匹配的对象键时,DisallowUnknowFields会导致解码器返回错误。
func (*Decoder) More
func (adapter *Decoder) More() bool
// 更多有更多吗
func (*Decoder) UseNumber
func (adapter *Decoder) UseNumber()
// UseNumber使解码器将一个数字解组到接口{}中作为一个数字,而不是浮点数64。
type DecoderExtension
type DecoderExtension map[reflect2.Type]ValDecoder
func (DecoderExtension) CreateDecoder
func (extension DecoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder
// CreateDecoder从映射中获取解码器
func (DecoderExtension) CreateEncoder
func (extension DecoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder
// CreateEncoder无操作
func (DecoderExtension) CreateMapKeyDecoder
func (extension DecoderExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder
// CreateMapKeyDecoder无操作
func (DecoderExtension) CreateMapKeyEncoder
func (extension DecoderExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder
// CreateMapKeyEncoder无操作
func (DecoderExtension) DecorateDecoder
func (extension DecoderExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder
// 装饰编码器无操作
func (DecoderExtension) DecorateEncoder
func (extension DecoderExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder
// 编码员无操作
func (DecoderExtension) UpdateStructDescriptor
func (extension DecoderExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor)
// UpdateStructDescriptor无操作
type DecoderFunc
type DecoderFunc func(ptr unsafe.Pointer, iter *Iterator)
// DecoderFunc类型解码器的函数形式
type DummyExtension
type DummyExtension struct {
}
// DummyExtension嵌入此类型,为所有扩展方法获取虚拟实现
func (*DummyExtension) CreateDecoder
func (extension *DummyExtension) CreateDecoder(typ reflect2.Type) ValDecoder
// CreateDecoder无操作
func (*DummyExtension) CreateEncoder
func (extension *DummyExtension) CreateEncoder(typ reflect2.Type) ValEncoder
// CreateEncoder无操作
func (*DummyExtension) CreateMapKeyDecoder
func (extension *DummyExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder
// CreateMapKeyDecoder无操作
func (*DummyExtension) CreateMapKeyEncoder
func (extension *DummyExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder
// CreateMapKeyEncoder无操作
func (*DummyExtension) DecorateDecoder
func (extension *DummyExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder
// 装饰编码器无操作
func (*DummyExtension) DecorateEncoder
func (extension *DummyExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder
// 编码员无操作
func (*DummyExtension) UpdateStructDescriptor
func (extension *DummyExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor)
// UpdateStructDescriptor无操作
type Encoder
type Encoder struct {
//包含已过滤或未报告的字段
}
// 编码器与json.Encoder相同
func NewEncoder
func NewEncoder(writer io.Writer) *Encoder
// NewEncoder与json.NewEncoder相同
func (*Encoder) Encode
func (adapter *Encoder) Encode(val interface{}) error
// 将接口{}编码为JSON到io.Writer
func (*Encoder) SetEscapeHTML
func (adapter *Encoder) SetEscapeHTML(escapeHTML bool)
// 默认情况下,SetEscapeHTML escape html,设置为false禁用
func (*Encoder) SetIndent
func (adapter *Encoder) SetIndent(prefix, indent string)
// 设置缩进设置缩进。不支持前缀
type EncoderExtension
type EncoderExtension map[reflect2.Type]ValEncoder
func (EncoderExtension) CreateDecoder
func (extension EncoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder
// CreateDecoder无操作
func (EncoderExtension) CreateEncoder
func (extension EncoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder
// CreateEncoder从地图获取编码器
func (EncoderExtension) CreateMapKeyDecoder
func (extension EncoderExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder
// CreateMapKeyDecoder无操作
func (EncoderExtension) CreateMapKeyEncoder
func (extension EncoderExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder
// CreateMapKeyEncoder无操作
func (EncoderExtension) DecorateDecoder
func (extension EncoderExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder
// 装饰编码器无操作
func (EncoderExtension) DecorateEncoder
func (extension EncoderExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder
// 编码员无操作
func (EncoderExtension) UpdateStructDescriptor
func (extension EncoderExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor)
// UpdateStructDescriptor无操作
type EncoderFunc
type EncoderFunc func(ptr unsafe.Pointer, stream *Stream)
// EncoderFunc类型编码器的函数形式
type Extension
type Extension interface {
UpdateStructDescriptor(structDescriptor *StructDescriptor)
CreateMapKeyDecoder(typ reflect2.Type) ValDecoder
CreateMapKeyEncoder(typ reflect2.Type) ValEncoder
CreateDecoder(typ reflect2.Type) ValDecoder
CreateEncoder(typ reflect2.Type) ValEncoder
DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder
DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder
}
// 扩展所有SPI的扩展名。通过指定备用编码器/解码器自定义编码/解码。还可以通过UpdateStructDescriptor重命名字段。
type IsEmbeddedPtrNil
type IsEmbeddedPtrNil interface {
IsEmbeddedPtrNil(ptr unsafe.Pointer)bool
}
type Iterator
type Iterator struct {
Error error
Attachment interface{} //为自定义解码器打开
//包含已过滤或未报告的字段
}
// 迭代器是一个类似io.Reader的对象,具有特定于JSON的读取函数。错误不会作为返回值返回,而是作为错误成员存储在此迭代器实例上。
func NewIterator
func NewIterator(cfg API) *Iterator
// NewIterator创建一个空的迭代器实例
func Parse
func Parse(cfg API, reader io.Reader, bufSize int) *Iterator
// Parse从io.Reader创建迭代器实例
func ParseBytes
func ParseBytes(cfg API, input []byte) *Iterator
// ParseBytes从字节数组创建迭代器实例
func ParseString
func ParseString(cfg API, input string) *Iterator
// ParseString从字符串创建迭代器实例
func (*Iterator) CurrentBuffer
func (iter *Iterator) CurrentBuffer() string
// CurrentBuffer将当前缓冲区作为字符串获取以用于调试
func (*Iterator) Pool
func (iter *Iterator) Pool() IteratorPool
// 池返回池可以提供更多具有相同配置的迭代器
func (*Iterator) Read
func (iter *Iterator) Read() interface{}
// 读取下一个JSON元素作为通用接口{}。
func (*Iterator) ReadAny
func (iter *Iterator) ReadAny() Any
// ReadAny将下一个JSON元素作为任意对象读取。这是一个更好的json.RawMessage。
func (*Iterator) ReadArray
func (iter *Iterator) ReadArray() (ret bool)
// ReadArray读取数组元素,告知数组是否有更多元素要读取。
func (*Iterator) ReadArrayCB
func (iter *Iterator) ReadArrayCB(callback func(*Iterator) bool) (ret bool)
// 带回调的ReadArrayCB读取数组
func (*Iterator) ReadBigFloat
func (iter *Iterator) ReadBigFloat() (ret *big.Float)
// 读大浮点读大,浮点
func (*Iterator) ReadBigInt
func (iter *Iterator) ReadBigInt() (ret *big.Int)
// ReadBigInt read big.Int
func (*Iterator) ReadBool
func (iter *Iterator) ReadBool() (ret bool)
// ReadBool将json对象读取为BoolValue
func (*Iterator) ReadFloat32
func (iter *Iterator) ReadFloat32() (ret float32)
// 读浮点32读浮点32
func (*Iterator) ReadFloat64
func (iter *Iterator) ReadFloat64() (ret float64)
// 读浮点64读浮点64
func (*Iterator) ReadInt
func (iter *Iterator) ReadInt() int
// 读入读入
func (*Iterator) ReadInt16
func (iter *Iterator) ReadInt16() (ret int16)
// ReadInt16 read int16
func (*Iterator) ReadInt32
func (iter *Iterator) ReadInt32() (ret int32)
// ReadInt32 read int32
func (*Iterator) ReadInt64
func (iter *Iterator) ReadInt64() (ret int64)
// 读取int64读取int64
func (*Iterator) ReadInt8
func (iter *Iterator) ReadInt8() (ret int8)
// ReadInt8 read int8
func (*Iterator) ReadMapCB
func (iter *Iterator) ReadMapCB(callback func(*Iterator, string) bool) bool
// ReadMapCB read map带回调,键可以是任何字符串
func (*Iterator) ReadNil
func (iter *Iterator) ReadNil() (ret bool)
// ReadNil将json对象读取为nil,并返回它是否为nil
func (*Iterator) ReadNumber
func (iter *Iterator) ReadNumber() (ret json.Number)
// ReadNumber读取json.Number
func (*Iterator) ReadObject
func (iter *Iterator) ReadObject() (ret string)
// ReadObject从对象中读取一个字段。如果对象结束,则返回空字符串。否则,返回字段名。
func (*Iterator) ReadObjectCB
func (iter *Iterator) ReadObjectCB(callback func(*Iterator, string) bool) bool
// ReadObjectCB带回调的read object,键仅为ascii,字段名未复制
func (*Iterator) ReadString
func (iter *Iterator) ReadString() (ret string)
// 从迭代器读取字符串
func (*Iterator) ReadStringAsSlice
func (iter *Iterator) ReadStringAsSlice() (ret []byte)
// ReadStringAsSlice从迭代器中读取字符串,而不复制到字符串形式。[]字节无法保留,因为它将在下一次迭代器调用后更改。
func (*Iterator) ReadUint
func (iter *Iterator) ReadUint() uint
// 读入读入
func (*Iterator) ReadUint16
func (iter *Iterator) ReadUint16() (ret uint16)
// 读uint16读uint16
func (*Iterator) ReadUint32
func (iter *Iterator) ReadUint32() (ret uint32)
// 读uint32读uint32
func (*Iterator) ReadUint64
func (iter *Iterator) ReadUint64() uint64
// 读uint64读uint64
func (*Iterator) ReadUint8
func (iter *Iterator) ReadUint8() (ret uint8)
// 读uint8读uint8
func (*Iterator) ReadVal
func (iter *Iterator) ReadVal(obj interface{})
// ReadVal将底层JSON复制到go接口中,与JSON.Unmarshal相同
func (*Iterator) ReportError
func (iter *Iterator) ReportError(operation string, msg string)
// ReportError使用当前位置在迭代器实例中记录错误。
func (*Iterator) Reset
func (iter *Iterator) Reset(reader io.Reader) *Iterator
// 通过指定其他读取器重置重用迭代器实例
func (*Iterator) ResetBytes
func (iter *Iterator) ResetBytes(input []byte) *Iterator
// ResetBytes通过指定另一个字节数组作为输入来重用迭代器实例
func (*Iterator) Skip
func (iter *Iterator) Skip()
// 跳过一个json对象并定位到下一个json对象
func (*Iterator) SkipAndAppendBytes
// 在v1.1.7中添加
func (iter *Iterator) SkipAndAppendBytes(buf []byte) []byte
// SkipPandAppendBytes跳过下一个JSON元素并将其内容附加到缓冲区,返回结果。
func (*Iterator) SkipAndReturnBytes
func (iter *Iterator) SkipAndReturnBytes() []byte
// SkipAndReturnBytes跳过下一个JSON元素,并将其内容作为[]字节返回。[]字节可以保留,它是数据的副本。
func (*Iterator) WhatIsNext
func (iter *Iterator) WhatIsNext() ValueType
// WhatIsNext获取相对下一个json元素的ValueType
type IteratorPool
type IteratorPool interface {
BorrowIterator(data []byte) *Iterator
ReturnIterator(iter *Iterator)
}
// 迭代器池具有相同配置的线程安全迭代器池
type Number
type Number string
func (Number) Float64
func (n Number) Float64() (float64, error)
// Float64将数字作为Float64返回。
func (Number) Int64
func (n Number) Int64() (int64, error)
// Int64将数字作为Int64返回。
func (Number) String
func (n Number) String() string
// 字符串返回数字的文字文本。
type OptionalDecoder
type OptionalDecoder struct {
ValueType reflect2.Type
ValueDecoder ValDecoder
}
func (*OptionalDecoder) Decode
func (decoder *OptionalDecoder) Decode(ptr unsafe.Pointer, iter *Iterator)
type OptionalEncoder
type OptionalEncoder struct {
ValueEncoder ValEncoder
}
func (*OptionalEncoder) Encode
func (encoder *OptionalEncoder) Encode(ptr unsafe.Pointer, stream *Stream)
func (*OptionalEncoder) IsEmpty
func (encoder *OptionalEncoder) IsEmpty(ptr unsafe.Pointer) bool
type RawMessage
type RawMessage []byte
// RawMessage使json替换为jsoniter
type Stream
type Stream struct {
Error error
Attachment interface{} //为自定义编码器打开
//包含已过滤或未报告的字段
}
// stream是一个类似io.Writer的对象,具有特定于JSON的写函数。错误不会作为返回值返回,而是作为错误成员存储在此流实例上。
func NewStream
func NewStream(cfg API, out io.Writer, bufSize int) *Stream
// NewStream创建新的流实例。cfg可以是jsoniter.ConfigDefault。如果写入内部缓冲区,out可以为零。bufSize是内部缓冲区的初始大小(以字节为单位)。
func (*Stream) Available
func (stream *Stream) Available() int
// Available返回缓冲区中未使用的字节数。
func (*Stream) Buffer
func (stream *Stream) Buffer() []byte
// 缓冲区如果writer为nil,则使用此方法获取结果
func (*Stream) Buffered
func (stream *Stream) Buffered() int
// Buffered返回已写入当前缓冲区的字节数。
func (*Stream) Flush
func (stream *Stream) Flush() error
// Flush将所有缓冲数据写入基础io.Writer。
func (*Stream) Pool
func (stream *Stream) Pool() StreamPool
// 池返回池可以提供更多具有相同配置的流
func (*Stream) Reset
func (stream *Stream) Reset(out io.Writer)
// 通过分配新的写入程序重置重用此流实例
func (*Stream) SetBuffer
func (stream *Stream) SetBuffer(buf []byte)
// SetBuffer允许直接附加到内部缓冲区
func (*Stream) Write
func (stream *Stream) Write(p []byte) (nn int, err error)
// Write将p的内容写入缓冲区。它返回写入的字节数。如果nn<len(p),它还会返回一个错误,解释写入为什么短。
func (*Stream) WriteArrayEnd
func (stream *Stream) WriteArrayEnd()
// writearlayend write]带有可能的缩进
func (*Stream) WriteArrayStart
func (stream *Stream) WriteArrayStart()
// WriteArrayStart write[具有可能的缩进
func (*Stream) WriteBool
func (stream *Stream) WriteBool(val bool)
// WriteBool将true或false写入流
func (*Stream) WriteEmptyArray
func (stream *Stream) WriteEmptyArray()
// WriteEmptyArray写入[]
func (*Stream) WriteEmptyObject
func (stream *Stream) WriteEmptyObject()
// WriteEmptyObject写入{}
func (*Stream) WriteFalse
func (stream *Stream) WriteFalse()
// WriteFalse将false写入流
func (*Stream) WriteFloat32
func (stream *Stream) WriteFloat32(val float32)
// WriteFloat32将float32写入流
func (*Stream) WriteFloat32Lossy
func (stream *Stream) WriteFloat32Lossy(val float32)
// WriteFloat32以仅6位数的精度将float32写入流,尽管速度要快得多
func (*Stream) WriteFloat64
func (stream *Stream) WriteFloat64(val float64)
// WriteFloat64将float64写入流
func (*Stream) WriteFloat64Lossy
func (stream *Stream) WriteFloat64Lossy(val float64)
// WriteFloat64有损写入float64到流,精度仅为6位,但速度要快得多
func (*Stream) WriteInt
func (stream *Stream) WriteInt(val int)
// WriteInt将int写入流
func (*Stream) WriteInt16
func (stream *Stream) WriteInt16(nval int16)
// WriteInt16将int16写入流
func (*Stream) WriteInt32
func (stream *Stream) WriteInt32(nval int32)
// WriteInt32将int32写入流
func (*Stream) WriteInt64
func (stream *Stream) WriteInt64(nval int64)
// WriteInt64将int64写入流
func (*Stream) WriteInt8
func (stream *Stream) WriteInt8(nval int8)
// WriteInt8将int8写入流
func (*Stream) WriteMore
func (stream *Stream) WriteMore()
// WriteMore write,可能有缩进
func (*Stream) WriteNil
func (stream *Stream) WriteNil()
// WriteNil将null写入流
func (*Stream) WriteObjectEnd
func (stream *Stream) WriteObjectEnd()
// WriteObjectEnd write}具有可能的缩进
func (*Stream) WriteObjectField
func (stream *Stream) WriteObjectField(field string)
// WriteObjectField写入“字段”:带有可能的缩进
func (*Stream) WriteObjectStart
func (stream *Stream) WriteObjectStart()
// WriteObject使用可能的缩进开始写入{
func (*Stream) WriteRaw
func (stream *Stream) WriteRaw(s string)
// WriteRaw不带引号地写出字符串,就像[]字节一样
func (*Stream) WriteString
func (stream *Stream) WriteString(s string)
// WriteString将字符串写入流而不使用html转义
func (*Stream) WriteStringWithHTMLEscaped
func (stream *Stream) WriteStringWithHTMLEscaped(s string)
// WriteStringWithHTMLEscaped使用转义的html特殊字符将字符串写入流
func (*Stream) WriteTrue
func (stream *Stream) WriteTrue()
// WriteTrue对流写入true
func (*Stream) WriteUint
func (stream *Stream) WriteUint(val uint)
// WriteUint将uint写入流
func (*Stream) WriteUint16
func (stream *Stream) WriteUint16(val uint16)
// WriteUint16将uint16写入流
func (*Stream) WriteUint32
func (stream *Stream) WriteUint32(val uint32)
// WriteUint32将uint32写入流
func (*Stream) WriteUint64
func (stream *Stream) WriteUint64(val uint64)
// WriteUint64将uint64写入流
func (*Stream) WriteUint8
func (stream *Stream) WriteUint8(val uint8)
// WriteUint8将uint8写入流
func (*Stream) WriteVal
func (stream *Stream) WriteVal(val interface{})
// WriteVal将go接口复制到基础JSON中,与JSON.Marshal相同
type StreamPool
type StreamPool interface {
type StreamPool interface {
BorrowStream(writer io.Writer) *Stream
ReturnStream(stream *Stream)
}
// StreamPool具有相同配置的线程安全流池
type StructDescriptor
type StructDescriptor struct {
Type reflect2.Type
Fields []*Binding
}
// StructDescriptor描述如何对结构进行编码/解码
func (*StructDescriptor) GetField
func (structDescriptor *StructDescriptor) GetField(fieldName string) *Binding
// GetField按名称从描述符中获取一个字段。不能在此处使用地图来保存现场订单。
type ValDecoder
type ValDecoder interface {
Decode(ptr unsafe.Pointer, iter *Iterator)
}
// ValDecoder是根据需要注册到缓存的内部类型。不要混淆jsoniter.ValDecoder和json.Decoder。对于json.Decoder的适配器,请参阅jsoniter.AdapterDecoder(todo链接)。
// 在类型上反射以创建解码器,然后缓存解码器。我们尽可能避免在值上反射,因为reflect.value本身将分配,但以下例外情况1。创建新值的实例,例如*int需要分配一个int 2。追加到切片,如果现有上限不够,将使用Reflect.New 3完成分配。分配给映射,键和值都将是reflect.value对于简单的结构绑定,它将是reflect.value-free和allocation-free
type ValEncoder
type ValEncoder interface {
IsEmpty(ptr unsafe.Pointer) bool
Encode(ptr unsafe.Pointer, stream *Stream)
}
// ValEncoder是根据需要注册到缓存的内部类型。不要混淆jsoniter.ValEncoder和json.Encoder。有关json.Encoder的适配器,请参阅jsoniter.AdapterEncoder(todo godoc链接)。
type ValueType
type ValueType int
// ValueType JSON元素的类型
const (
//InvalidValue无效的JSON元素
InvalidValue ValueType = iota
//StringValue JSON元素“string”
StringValue
//NumberValue JSON元素100或0.10
NumberValue
//NilValue JSON元素null
NilValue
//布尔值JSON元素true或false
BoolValue
//ArrayValue JSON元素[]
ArrayValue
//ObjectValue JSON元素{}
ObjectValue
)
json-iterator 库函数
最新推荐文章于 2024-08-10 08:10:01 发布