mirror of
https://github.com/json-iterator/go.git
synced 2025-02-01 19:14:29 +02:00
Merge branch 'master' of https://github.com/json-iterator/go
This commit is contained in:
commit
4ae426c4b7
@ -1,7 +1,7 @@
|
||||
| json type \ dest type | bool | int | uint | float |string|
|
||||
| --- | --- | --- | --- |--|--|
|
||||
| number | positive => true <br/> negative => true <br/> zero => false| 23.2 => 23 <br/> -32.1 => -32| 12.1 => 12 <br/> -12.1 => 0|as normal||
|
||||
| string | empty string => false <br/> string "0" => false <br/> other strings => true | "123.32" => 123 <br/> "-123.4" => -123 <br/> "123.23xxxw" => 123 <br/> "abcde12" => 0 <br/> "-32.1" => -32| 13.2 => 13 <br/> -1.1 => 0 |12.1 => 12.1 <br/> -12.3 => -12.3<br/> 12.4xxa => 12.4 <br/> +1.1e2 =>110 ||
|
||||
| bool | true => true <br/> false => false| true => 1 <br/> false => 0 | true => 1 <br/> false => 0 |true => 1 <br/>false => 0||
|
||||
| object | true | 0 | 0 |0||
|
||||
| array | empty array => false <br/> nonempty array => true| [] => 0 <br/> [1,2] => 1 | [] => 0 <br/> [1,2] => 1 |[] => 0<br/>[1,2] => 1||
|
||||
| number | positive => true <br/> negative => true <br/> zero => false| 23.2 => 23 <br/> -32.1 => -32| 12.1 => 12 <br/> -12.1 => 0|as normal|same as origin|
|
||||
| string | empty string => false <br/> string "0" => false <br/> other strings => true | "123.32" => 123 <br/> "-123.4" => -123 <br/> "123.23xxxw" => 123 <br/> "abcde12" => 0 <br/> "-32.1" => -32| 13.2 => 13 <br/> -1.1 => 0 |12.1 => 12.1 <br/> -12.3 => -12.3<br/> 12.4xxa => 12.4 <br/> +1.1e2 =>110 |same as origin|
|
||||
| bool | true => true <br/> false => false| true => 1 <br/> false => 0 | true => 1 <br/> false => 0 |true => 1 <br/>false => 0|true => "true" <br/> false => "false"|
|
||||
| object | true | 0 | 0 |0|originnal json|
|
||||
| array | empty array => false <br/> nonempty array => true| [] => 0 <br/> [1,2] => 1 | [] => 0 <br/> [1,2] => 1 |[] => 0<br/>[1,2] => 1|original json|
|
42
jsoniter_encode_interface_test.go
Normal file
42
jsoniter_encode_interface_test.go
Normal file
@ -0,0 +1,42 @@
|
||||
package jsoniter
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_encode_interface(t *testing.T) {
|
||||
should := require.New(t)
|
||||
var a interface{}
|
||||
a = int8(10)
|
||||
str, err := MarshalToString(a)
|
||||
should.Nil(err)
|
||||
should.Equal(str, "10")
|
||||
a = float32(3)
|
||||
str, err = MarshalToString(a)
|
||||
should.Nil(err)
|
||||
should.Equal(str, "3")
|
||||
a = map[string]interface{}{"abc": 1}
|
||||
str, err = MarshalToString(a)
|
||||
should.Nil(err)
|
||||
should.Equal(str, `{"abc":1}`)
|
||||
a = uintptr(1)
|
||||
str, err = MarshalToString(a)
|
||||
should.Nil(err)
|
||||
should.Equal(str, "1")
|
||||
a = uint(1)
|
||||
str, err = MarshalToString(a)
|
||||
should.Nil(err)
|
||||
should.Equal(str, "1")
|
||||
a = uint8(1)
|
||||
str, err = MarshalToString(a)
|
||||
should.Nil(err)
|
||||
should.Equal(str, "1")
|
||||
a = json.RawMessage("abc")
|
||||
MarshalToString(a)
|
||||
str, err = MarshalToString(a)
|
||||
should.Nil(err)
|
||||
should.Equal(str, "abc")
|
||||
}
|
@ -94,7 +94,16 @@ func Test_read_normal_string(t *testing.T) {
|
||||
func Test_read_exotic_string(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
`"hel\"lo"`: `hel"lo`,
|
||||
`"hel\nlo"`: "hel\nlo",
|
||||
`"hel\\\/lo"`: `hel\/lo`,
|
||||
`"hel\\blo"`: `hel\blo`,
|
||||
`"hel\\\blo"`: "hel\\\blo",
|
||||
`"hel\\nlo"`: `hel\nlo`,
|
||||
`"hel\\\nlo"`: "hel\\\nlo",
|
||||
`"hel\\tlo"`: `hel\tlo`,
|
||||
`"hel\\flo"`: `hel\flo`,
|
||||
`"hel\\\flo"`: "hel\\\flo",
|
||||
`"hel\\\rlo"`: "hel\\\rlo",
|
||||
`"hel\\\tlo"`: "hel\\\tlo",
|
||||
`"\u4e2d\u6587"`: "中文",
|
||||
`"\ud83d\udc4a"`: "\xf0\x9f\x91\x8a", // surrogate
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user