mirror of
https://github.com/json-iterator/go.git
synced 2025-04-23 11:37:32 +02:00
Use json.Number as the return
This commit is contained in:
parent
7b1fd129cf
commit
be9d4ded4f
@ -1,8 +1,10 @@
|
|||||||
package jsoniter
|
package jsoniter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ValueType the type for JSON element
|
// ValueType the type for JSON element
|
||||||
@ -274,7 +276,8 @@ func (iter *Iterator) Read() interface{} {
|
|||||||
return iter.ReadString()
|
return iter.ReadString()
|
||||||
case Number:
|
case Number:
|
||||||
if iter.cfg.configBeforeFrozen.UseNumber {
|
if iter.cfg.configBeforeFrozen.UseNumber {
|
||||||
return iter.ReadInt()
|
num := iter.ReadInt64()
|
||||||
|
return json.Number(strconv.FormatInt(num, 10))
|
||||||
}
|
}
|
||||||
return iter.ReadFloat64()
|
return iter.ReadFloat64()
|
||||||
case Nil:
|
case Nil:
|
||||||
|
@ -2,6 +2,7 @@ package jsoniter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
@ -45,9 +46,8 @@ func Test_iterator_use_number(t *testing.T) {
|
|||||||
t.Run(fmt.Sprintf("%v", input), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%v", input), func(t *testing.T) {
|
||||||
should := require.New(t)
|
should := require.New(t)
|
||||||
iter := ParseString(Config{UseNumber: true}.Froze(), input)
|
iter := ParseString(Config{UseNumber: true}.Froze(), input)
|
||||||
expected, err := strconv.ParseInt(input, 10, 32)
|
expected := json.Number(input)
|
||||||
should.Nil(err)
|
should.Equal(expected, iter.Read())
|
||||||
should.Equal(int(expected), iter.Read())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user