mirror of
https://github.com/json-iterator/go.git
synced 2025-03-23 21:09:11 +02:00
Merge pull request #41 from 1046102779/master
解析时,如果输出参数不是指针类型,直接报错,避免程序挂掉
This commit is contained in:
commit
6509ba05df
@ -1,8 +1,10 @@
|
||||
package jsoniter
|
||||
|
||||
import (
|
||||
"io"
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// Unmarshal adapts to json/encoding Unmarshal API
|
||||
@ -12,6 +14,11 @@ import (
|
||||
func Unmarshal(data []byte, v interface{}) error {
|
||||
data = data[:lastNotSpacePos(data)]
|
||||
iter := ParseBytes(data)
|
||||
typ := reflect.TypeOf(v)
|
||||
if typ.Kind() != reflect.Ptr {
|
||||
// return non-pointer error
|
||||
return errors.New("the second param must be ptr type")
|
||||
}
|
||||
iter.ReadVal(v)
|
||||
if iter.head == iter.tail {
|
||||
iter.loadMore()
|
||||
@ -157,4 +164,4 @@ func (adapter *AdaptedEncoder) Encode(val interface{}) error {
|
||||
|
||||
func (adapter *AdaptedEncoder) SetIndent(prefix, indent string) {
|
||||
// not implemented yet
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user