mirror of
https://github.com/json-iterator/go.git
synced 2025-04-14 11:18:49 +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,68 +29,36 @@ func (any *objectLazyAny) ToBool() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (any *objectLazyAny) ToInt() int {
|
func (any *objectLazyAny) ToInt() int {
|
||||||
if any.ToBool() {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (any *objectLazyAny) ToInt32() int32 {
|
func (any *objectLazyAny) ToInt32() int32 {
|
||||||
if any.ToBool() {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (any *objectLazyAny) ToInt64() int64 {
|
func (any *objectLazyAny) ToInt64() int64 {
|
||||||
if any.ToBool() {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (any *objectLazyAny) ToUint() uint {
|
func (any *objectLazyAny) ToUint() uint {
|
||||||
if any.ToBool() {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (any *objectLazyAny) ToUint32() uint32 {
|
func (any *objectLazyAny) ToUint32() uint32 {
|
||||||
if any.ToBool() {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (any *objectLazyAny) ToUint64() uint64 {
|
func (any *objectLazyAny) ToUint64() uint64 {
|
||||||
if any.ToBool() {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (any *objectLazyAny) ToFloat32() float32 {
|
func (any *objectLazyAny) ToFloat32() float32 {
|
||||||
if any.ToBool() {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (any *objectLazyAny) ToFloat64() float64 {
|
func (any *objectLazyAny) ToFloat64() float64 {
|
||||||
if any.ToBool() {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (any *objectLazyAny) ToString() string {
|
func (any *objectLazyAny) ToString() string {
|
||||||
return *(*string)(unsafe.Pointer(&any.buf))
|
return *(*string)(unsafe.Pointer(&any.buf))
|
||||||
|
@ -30,6 +30,8 @@ var intConvertMap = map[string]int{
|
|||||||
"-": 0,
|
"-": 0,
|
||||||
"[]": 0,
|
"[]": 0,
|
||||||
"[1,2]": 1,
|
"[1,2]": 1,
|
||||||
|
// object in php cannot convert to int
|
||||||
|
"{}": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_read_any_to_int(t *testing.T) {
|
func Test_read_any_to_int(t *testing.T) {
|
||||||
@ -75,6 +77,7 @@ var uintConvertMap = map[string]int{
|
|||||||
"-": 0,
|
"-": 0,
|
||||||
"[]": 0,
|
"[]": 0,
|
||||||
"[1,2]": 1,
|
"[1,2]": 1,
|
||||||
|
"{}": 0,
|
||||||
// TODO need to solve
|
// TODO need to solve
|
||||||
//"-1.1": 1,
|
//"-1.1": 1,
|
||||||
//"-321.1": 321,
|
//"-321.1": 321,
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package jsoniter
|
package jsoniter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/json-iterator/go/require"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/json-iterator/go/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_read_object_as_any(t *testing.T) {
|
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, len(any.Keys()))
|
||||||
should.Equal(2, any.Size())
|
should.Equal(2, any.Size())
|
||||||
should.True(any.ToBool())
|
should.True(any.ToBool())
|
||||||
should.Equal(1, any.ToInt())
|
should.Equal(0, any.ToInt())
|
||||||
should.Equal(Object, any.ValueType())
|
should.Equal(Object, any.ValueType())
|
||||||
should.Nil(any.LastError())
|
should.Nil(any.LastError())
|
||||||
should.Equal("b", any.GetObject()["a"].ToString())
|
should.Equal("b", any.GetObject()["a"].ToString())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user