You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-15 22:50:24 +02:00
map any support get all
This commit is contained in:
@ -503,14 +503,28 @@ func (any *objectAny) Get(path ...interface{}) Any {
|
||||
return any
|
||||
}
|
||||
var element Any
|
||||
key, ok := path[0].(string)
|
||||
if ok {
|
||||
element = any.fillCacheUntil(key)
|
||||
switch firstPath := path[0].(type) {
|
||||
case string:
|
||||
element = any.fillCacheUntil(firstPath)
|
||||
if element == nil {
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", key, any.cache)}
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
|
||||
}
|
||||
} else {
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", key, any.cache)}
|
||||
case int32:
|
||||
if '*' == firstPath {
|
||||
any.fillCache()
|
||||
mappedAll := map[string]Any{}
|
||||
for key, value := range any.cache {
|
||||
mapped := value.Get(path[1:]...)
|
||||
if mapped.ValueType() != Invalid {
|
||||
mappedAll[key] = mapped
|
||||
}
|
||||
}
|
||||
return wrapMap(mappedAll)
|
||||
} else {
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
|
||||
}
|
||||
default:
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
|
||||
}
|
||||
if len(path) == 1 {
|
||||
return element
|
||||
@ -738,14 +752,28 @@ func (any *mapAny) Get(path ...interface{}) Any {
|
||||
return any
|
||||
}
|
||||
var element Any
|
||||
key, ok := path[0].(string)
|
||||
if ok {
|
||||
element = any.fillCacheUntil(key)
|
||||
switch firstPath := path[0].(type) {
|
||||
case string:
|
||||
element = any.fillCacheUntil(firstPath)
|
||||
if element == nil {
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", key, any.cache)}
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
|
||||
}
|
||||
} else {
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", key, any.cache)}
|
||||
case int32:
|
||||
if '*' == firstPath {
|
||||
any.fillCache()
|
||||
mappedAll := map[string]Any{}
|
||||
for key, value := range any.cache {
|
||||
mapped := value.Get(path[1:]...)
|
||||
if mapped.ValueType() != Invalid {
|
||||
mappedAll[key] = mapped
|
||||
}
|
||||
}
|
||||
return wrapMap(mappedAll)
|
||||
} else {
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
|
||||
}
|
||||
default:
|
||||
element = &invalidAny{baseAny{}, fmt.Errorf("%v not found in %v", firstPath, any.cache)}
|
||||
}
|
||||
if len(path) == 1 {
|
||||
return element
|
||||
|
Reference in New Issue
Block a user