You've already forked json-iterator
mirror of
https://github.com/json-iterator/go.git
synced 2025-06-15 22:50:24 +02:00
#50 map key unlike object field, can contain escaped char
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"github.com/json-iterator/go/require"
|
||||
"math/big"
|
||||
"testing"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func Test_read_map(t *testing.T) {
|
||||
@ -101,3 +102,28 @@ func Test_decode_TextMarshaler_key_map(t *testing.T) {
|
||||
should.Nil(err)
|
||||
should.Equal(`{"1":"2"}`, str)
|
||||
}
|
||||
|
||||
|
||||
|
||||
func Test_map_key_with_escaped_char(t *testing.T) {
|
||||
type Ttest struct {
|
||||
Map map[string]string
|
||||
}
|
||||
var jsonBytes = []byte(`
|
||||
{
|
||||
"Map":{
|
||||
"k\"ey": "val"
|
||||
}
|
||||
}`)
|
||||
should := require.New(t)
|
||||
{
|
||||
var obj Ttest
|
||||
should.Nil(json.Unmarshal(jsonBytes, &obj))
|
||||
should.Equal(map[string]string{"k\"ey":"val"}, obj.Map)
|
||||
}
|
||||
{
|
||||
var obj Ttest
|
||||
should.Nil(Unmarshal(jsonBytes, &obj))
|
||||
should.Equal(map[string]string{"k\"ey":"val"}, obj.Map)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user