1
0
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:
Tao Wen
2017-06-12 10:13:13 +08:00
parent 6bd13c2948
commit 3307ce3ba2
3 changed files with 68 additions and 2 deletions

View File

@ -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)
}
}