You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-15 22:50:24 +02:00
Decoder doc
This commit is contained in:
@ -8,9 +8,7 @@ import (
|
|||||||
// Unmarshal adapts to json/encoding Unmarshal API
|
// Unmarshal adapts to json/encoding Unmarshal API
|
||||||
//
|
//
|
||||||
// Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v.
|
// Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v.
|
||||||
// <l>https://godoc.org/encoding/json#Unmarshal</l>
|
// Refer to https://godoc.org/encoding/json#Unmarshal for more information
|
||||||
// linktest: https://godoc.org/encoding/json#Unmarshal
|
|
||||||
// <a href="https://godoc.org/encoding/json#Unmarshal">link test</a>
|
|
||||||
func Unmarshal(data []byte, v interface{}) error {
|
func Unmarshal(data []byte, v interface{}) error {
|
||||||
data = data[:lastNotSpacePos(data)]
|
data = data[:lastNotSpacePos(data)]
|
||||||
iter := ParseBytes(data)
|
iter := ParseBytes(data)
|
||||||
@ -89,6 +87,7 @@ func UnmarshalAnyFromString(str string) (Any, error) {
|
|||||||
// Marshal adapts to json/encoding Marshal API
|
// Marshal adapts to json/encoding Marshal API
|
||||||
//
|
//
|
||||||
// Marshal returns the JSON encoding of v, adapts to json/encoding Marshal API
|
// Marshal returns the JSON encoding of v, adapts to json/encoding Marshal API
|
||||||
|
// Refer to https://godoc.org/encoding/json#Marshal for more information
|
||||||
func Marshal(v interface{}) ([]byte, error) {
|
func Marshal(v interface{}) ([]byte, error) {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
stream := NewStream(buf, 512)
|
stream := NewStream(buf, 512)
|
||||||
@ -111,11 +110,16 @@ func MarshalToString(v interface{}) (string, error) {
|
|||||||
// NewDecoder adapts to json/stream NewDecoder API.
|
// NewDecoder adapts to json/stream NewDecoder API.
|
||||||
//
|
//
|
||||||
// NewDecoder returns a new decoder that reads from r.
|
// NewDecoder returns a new decoder that reads from r.
|
||||||
|
//
|
||||||
|
// Instead of a json/encoding Decoder, an AdaptedDecoder is returned
|
||||||
|
// Refer to https://godoc.org/encoding/json#NewDecoder for more information
|
||||||
func NewDecoder(reader io.Reader) *AdaptedDecoder {
|
func NewDecoder(reader io.Reader) *AdaptedDecoder {
|
||||||
iter := Parse(reader, 512)
|
iter := Parse(reader, 512)
|
||||||
return &AdaptedDecoder{iter}
|
return &AdaptedDecoder{iter}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdaptedDecoder reads and decodes JSON values from an input stream.
|
||||||
|
// AdaptedDecoder provides identical APIs with json/stream Decoder (Token() and UseNumber() are in progress)
|
||||||
type AdaptedDecoder struct {
|
type AdaptedDecoder struct {
|
||||||
iter *Iterator
|
iter *Iterator
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user