diff --git a/jsoniter_map_test.go b/jsoniter_map_test.go index d69f073..b47ee57 100644 --- a/jsoniter_map_test.go +++ b/jsoniter_map_test.go @@ -10,6 +10,7 @@ func Test_read_map(t *testing.T) { iter := ParseString(`{"hello": "world"}`) m := map[string]string{"1": "2"} iter.Read(&m) + copy(iter.buf, []byte{0,0,0,0,0,0}) if !reflect.DeepEqual(map[string]string{"1": "2", "hello": "world"}, m) { fmt.Println(iter.Error) t.Fatal(m) diff --git a/jsoniter_reflect.go b/jsoniter_reflect.go index 946dd8b..033d982 100644 --- a/jsoniter_reflect.go +++ b/jsoniter_reflect.go @@ -327,7 +327,7 @@ func (decoder *mapDecoder) decode(ptr unsafe.Pointer, iter *Iterator) { for field := iter.ReadObject(); field != ""; field = iter.ReadObject() { elem := reflect.New(decoder.elemType) decoder.elemDecoder.decode(unsafe.Pointer(elem.Pointer()), iter) - realVal.SetMapIndex(reflect.ValueOf(field), elem.Elem()) + realVal.SetMapIndex(reflect.ValueOf(string([]byte(field))), elem.Elem()) } } @@ -514,7 +514,7 @@ func (iter *Iterator) ReadAny() (ret *Any) { if iter.Error != nil { return } - val[field] = element.val + val[string([]byte(field))] = element.val } return MakeAny(val) default: