mirror of
https://github.com/json-iterator/go.git
synced 2025-02-07 19:30:06 +02:00
object cannot covert to int/float in php, so change covert result to zero
This commit is contained in:
parent
d8dbf14af4
commit
ac8dd56dfb
@ -29,67 +29,35 @@ func (any *objectLazyAny) ToBool() bool {
|
||||
}
|
||||
|
||||
func (any *objectLazyAny) ToInt() int {
|
||||
if any.ToBool() {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (any *objectLazyAny) ToInt32() int32 {
|
||||
if any.ToBool() {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (any *objectLazyAny) ToInt64() int64 {
|
||||
if any.ToBool() {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (any *objectLazyAny) ToUint() uint {
|
||||
if any.ToBool() {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (any *objectLazyAny) ToUint32() uint32 {
|
||||
if any.ToBool() {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (any *objectLazyAny) ToUint64() uint64 {
|
||||
if any.ToBool() {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (any *objectLazyAny) ToFloat32() float32 {
|
||||
if any.ToBool() {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (any *objectLazyAny) ToFloat64() float64 {
|
||||
if any.ToBool() {
|
||||
return 1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (any *objectLazyAny) ToString() string {
|
||||
|
@ -30,6 +30,8 @@ var intConvertMap = map[string]int{
|
||||
"-": 0,
|
||||
"[]": 0,
|
||||
"[1,2]": 1,
|
||||
// object in php cannot convert to int
|
||||
"{}": 0,
|
||||
}
|
||||
|
||||
func Test_read_any_to_int(t *testing.T) {
|
||||
@ -75,6 +77,7 @@ var uintConvertMap = map[string]int{
|
||||
"-": 0,
|
||||
"[]": 0,
|
||||
"[1,2]": 1,
|
||||
"{}": 0,
|
||||
// TODO need to solve
|
||||
//"-1.1": 1,
|
||||
//"-321.1": 321,
|
||||
|
@ -1,8 +1,9 @@
|
||||
package jsoniter
|
||||
|
||||
import (
|
||||
"github.com/json-iterator/go/require"
|
||||
"testing"
|
||||
|
||||
"github.com/json-iterator/go/require"
|
||||
)
|
||||
|
||||
func Test_read_object_as_any(t *testing.T) {
|
||||
@ -18,7 +19,7 @@ func Test_read_object_as_any(t *testing.T) {
|
||||
should.Equal(2, len(any.Keys()))
|
||||
should.Equal(2, any.Size())
|
||||
should.True(any.ToBool())
|
||||
should.Equal(1, any.ToInt())
|
||||
should.Equal(0, any.ToInt())
|
||||
should.Equal(Object, any.ValueType())
|
||||
should.Nil(any.LastError())
|
||||
should.Equal("b", any.GetObject()["a"].ToString())
|
||||
|
Loading…
x
Reference in New Issue
Block a user