Documentation
¶
Index ¶
- type Decoder
- type Encoder
- func (e *Encoder) Bytes() []byte
- func (e *Encoder) EndArray()
- func (e *Encoder) EndObject()
- func (e *Encoder) StartArray()
- func (e *Encoder) StartObject()
- func (e *Encoder) WriteBool(b bool)
- func (e *Encoder) WriteFloat(n float64, bitSize int)
- func (e *Encoder) WriteInt(n int64)
- func (e *Encoder) WriteName(s string) error
- func (e *Encoder) WriteNull()
- func (e *Encoder) WriteString(s string) error
- func (e *Encoder) WriteUint(n uint64)
- type Type
- type Value
- func (v Value) Bool() (bool, error)
- func (v Value) Float(bitSize int) (float64, error)
- func (v Value) Int(bitSize int) (int64, error)
- func (v Value) Name() (string, error)
- func (v Value) Position() (int, int)
- func (v Value) Raw() string
- func (v Value) String() string
- func (v Value) Type() Type
- func (v Value) Uint(bitSize int) (uint64, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is a token-based JSON decoder.
func NewDecoder ¶
NewDecoder returns a Decoder to read the given []byte.
func (*Decoder) Clone ¶
Clone returns a copy of the Decoder for use in reading ahead the next JSON object, array or other values without affecting current Decoder.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder provides methods to write out JSON constructs and values. The user is responsible for producing valid sequences of JSON constructs and values.
func NewEncoder ¶
NewEncoder returns an Encoder.
If indent is a non-empty string, it causes every entry for an Array or Object to be preceded by the indent and trailed by a newline.
func (*Encoder) StartObject ¶
func (e *Encoder) StartObject()
StartObject writes out the '{' symbol.
func (*Encoder) WriteFloat ¶
WriteFloat writes out the given float and bitSize in JSON number value.
func (*Encoder) WriteName ¶
WriteName writes out the given string in JSON string value and the name separator ':'.
func (*Encoder) WriteString ¶
WriteString writes out the given string in JSON string value.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value contains a JSON type and value parsed from calling Decoder.Read. For JSON boolean and string, it holds the converted value in boo and str fields respectively. For JSON number, input field holds a valid number which is converted only in Int or Float. Other JSON types do not require any additional data.
func (Value) Float ¶
Float returns the floating-point number if token is Number, else it will return an error.
The floating-point precision is specified by the bitSize parameter: 32 for float32 or 64 for float64. If bitSize=32, the result still has type float64, but it will be convertible to float32 without changing its value. It will return an error if the number exceeds the floating point limits for given bitSize.
func (Value) Int ¶
Int returns the signed integer number if token is Number, else it will return an error.
The given bitSize specifies the integer type that the result must fit into. It returns an error if the number is not an integer value or if the result exceeds the limits for given bitSize.
func (Value) String ¶
String returns the string value for a JSON string token or the read value in string if token is not a string.
func (Value) Uint ¶
Uint returns the signed integer number if token is Number, else it will return an error.
The given bitSize specifies the unsigned integer type that the result must fit into. It returns an error if the number is not an unsigned integer value or if the result exceeds the limits for given bitSize.