You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-15 22:50:24 +02:00
Any Get will never return nil
This commit is contained in:
@ -2,6 +2,7 @@ package jsoniter
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type arrayLazyAny struct {
|
||||
@ -13,6 +14,10 @@ type arrayLazyAny struct {
|
||||
remaining []byte
|
||||
}
|
||||
|
||||
func (any *arrayLazyAny) ValueType() ValueType {
|
||||
return Array
|
||||
}
|
||||
|
||||
func (any *arrayLazyAny) Parse() *Iterator {
|
||||
iter := any.iter
|
||||
if iter == nil {
|
||||
@ -176,12 +181,20 @@ func (any *arrayLazyAny) Get(path ...interface{}) Any {
|
||||
if len(path) == 0 {
|
||||
return any
|
||||
}
|
||||
if len(path) == 1 {
|
||||
idx := path[0].(int)
|
||||
return any.fillCacheUntil(idx)
|
||||
var element Any
|
||||
idx, ok := path[0].(int)
|
||||
if ok {
|
||||
element = any.fillCacheUntil(idx)
|
||||
if element == nil {
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", idx, any.cache)}
|
||||
}
|
||||
} else {
|
||||
idx := path[0].(int)
|
||||
return any.fillCacheUntil(idx).Get(path[1:]...)
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", idx, any.cache)}
|
||||
}
|
||||
if len(path) == 1 {
|
||||
return element
|
||||
} else {
|
||||
return element.Get(path[1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user