|
@@ -8,10 +8,12 @@ import (
|
|
"strings"
|
|
"strings"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+// Marshal marshals v into json bytes.
|
|
func Marshal(v interface{}) ([]byte, error) {
|
|
func Marshal(v interface{}) ([]byte, error) {
|
|
return json.Marshal(v)
|
|
return json.Marshal(v)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Unmarshal unmarshals data bytes into v.
|
|
func Unmarshal(data []byte, v interface{}) error {
|
|
func Unmarshal(data []byte, v interface{}) error {
|
|
decoder := json.NewDecoder(bytes.NewReader(data))
|
|
decoder := json.NewDecoder(bytes.NewReader(data))
|
|
if err := unmarshalUseNumber(decoder, v); err != nil {
|
|
if err := unmarshalUseNumber(decoder, v); err != nil {
|
|
@@ -21,6 +23,7 @@ func Unmarshal(data []byte, v interface{}) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// UnmarshalFromString unmarshals v from str.
|
|
func UnmarshalFromString(str string, v interface{}) error {
|
|
func UnmarshalFromString(str string, v interface{}) error {
|
|
decoder := json.NewDecoder(strings.NewReader(str))
|
|
decoder := json.NewDecoder(strings.NewReader(str))
|
|
if err := unmarshalUseNumber(decoder, v); err != nil {
|
|
if err := unmarshalUseNumber(decoder, v); err != nil {
|
|
@@ -30,6 +33,7 @@ func UnmarshalFromString(str string, v interface{}) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// UnmarshalFromReader unmarshals v from reader.
|
|
func UnmarshalFromReader(reader io.Reader, v interface{}) error {
|
|
func UnmarshalFromReader(reader io.Reader, v interface{}) error {
|
|
var buf strings.Builder
|
|
var buf strings.Builder
|
|
teeReader := io.TeeReader(reader, &buf)
|
|
teeReader := io.TeeReader(reader, &buf)
|