1
0
mirror of https://github.com/json-iterator/go.git synced 2025-03-23 21:09:11 +02:00

add Any GetInterface

This commit is contained in:
Tao Wen 2017-01-26 15:44:10 +08:00
parent 97472ecd96
commit 9abc2f52b0
9 changed files with 46 additions and 0 deletions

View File

@ -18,6 +18,7 @@ type Any interface {
SetArray(newList []Any) bool
GetObject() map[string]Any
SetObject(map[string]Any) bool
GetInterface() interface{}
WriteTo(stream *Stream)
Parse() *Iterator
}

View File

@ -270,4 +270,9 @@ func (any *arrayLazyAny) WriteTo(stream *Stream) {
any.fillCache()
stream.WriteVal(any.cache)
}
}
func (any *arrayLazyAny) GetInterface() interface{} {
any.fillCache()
return any.cache
}

View File

@ -44,6 +44,10 @@ func (any *trueAny) Parse() *Iterator {
return nil
}
func (any *trueAny) GetInterface() interface{} {
return true
}
type falseAny struct {
baseAny
}
@ -87,3 +91,7 @@ func (any *falseAny) WriteTo(stream *Stream) {
func (any *falseAny) Parse() *Iterator {
return nil
}
func (any *falseAny) GetInterface() interface{} {
return false
}

View File

@ -73,4 +73,9 @@ func (any *floatLazyAny) ToString() string {
func (any *floatLazyAny) WriteTo(stream *Stream) {
stream.Write(any.buf)
}
func (any *floatLazyAny) GetInterface() interface{} {
any.fillCache()
return any.cache
}

View File

@ -76,6 +76,11 @@ func (any *intLazyAny) WriteTo(stream *Stream) {
stream.Write(any.buf)
}
func (any *intLazyAny) GetInterface() interface{} {
any.fillCache()
return any.cache
}
type intAny struct {
baseAny
err error
@ -120,4 +125,8 @@ func (any *intAny) WriteTo(stream *Stream) {
func (any *intAny) Parse() *Iterator {
return nil
}
func (any *intAny) GetInterface() interface{} {
return any.val
}

View File

@ -46,3 +46,7 @@ func (any *invalidAny) Get(path ...interface{}) Any {
func (any *invalidAny) Parse() *Iterator {
return nil
}
func (any *invalidAny) GetInterface() interface{} {
return nil
}

View File

@ -42,4 +42,8 @@ func (any *nilAny) WriteTo(stream *Stream) {
func (any *nilAny) Parse() *Iterator {
return nil
}
func (any *nilAny) GetInterface() interface{} {
return nil
}

View File

@ -291,4 +291,9 @@ func (any *objectLazyAny) WriteTo(stream *Stream) {
any.fillCache()
stream.WriteVal(any.cache)
}
}
func (any *objectLazyAny) GetInterface() interface{} {
any.fillCache()
return any.cache
}

View File

@ -100,4 +100,9 @@ func (any *stringLazyAny) ToString() string {
func (any *stringLazyAny) WriteTo(stream *Stream) {
stream.Write(any.buf)
}
func (any *stringLazyAny) GetInterface() interface{} {
any.fillCache()
return any.cache
}