mirror of https://github.com/goccy/go-json.git
Fix decoding of map type
This commit is contained in:
parent
fa87dde0c3
commit
9053c385ea
|
@ -130,27 +130,24 @@ func (d *mapDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64,
|
||||||
cursor++
|
cursor++
|
||||||
return cursor, nil
|
return cursor, nil
|
||||||
}
|
}
|
||||||
for ; cursor < buflen; cursor++ {
|
for {
|
||||||
var key interface{}
|
k := unsafe_New(d.keyType)
|
||||||
keyCursor, err := d.setKey(buf, cursor, &key)
|
keyCursor, err := d.keyDecoder.decode(buf, cursor, k)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
cursor = keyCursor
|
cursor = keyCursor
|
||||||
cursor = skipWhiteSpace(buf, cursor)
|
cursor = skipWhiteSpace(buf, keyCursor)
|
||||||
if buf[cursor] != ':' {
|
if buf[cursor] != ':' {
|
||||||
return 0, errExpected("colon after object key", cursor)
|
return 0, errExpected("colon after object key", cursor)
|
||||||
}
|
}
|
||||||
cursor++
|
cursor++
|
||||||
if cursor >= buflen {
|
v := unsafe_New(d.valueType)
|
||||||
return 0, errUnexpectedEndOfJSON("map", cursor)
|
valueCursor, err := d.valueDecoder.decode(buf, cursor, v)
|
||||||
}
|
|
||||||
var value interface{}
|
|
||||||
valueCursor, err := d.setValue(buf, cursor, &value)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
mapassign(d.mapType, mapValue, unsafe.Pointer(&key), unsafe.Pointer(&value))
|
mapassign(d.mapType, mapValue, k, v)
|
||||||
cursor = skipWhiteSpace(buf, valueCursor)
|
cursor = skipWhiteSpace(buf, valueCursor)
|
||||||
if buf[cursor] == '}' {
|
if buf[cursor] == '}' {
|
||||||
**(**unsafe.Pointer)(unsafe.Pointer(&p)) = mapValue
|
**(**unsafe.Pointer)(unsafe.Pointer(&p)) = mapValue
|
||||||
|
@ -160,6 +157,7 @@ func (d *mapDecoder) decode(buf []byte, cursor int64, p unsafe.Pointer) (int64,
|
||||||
if buf[cursor] != ',' {
|
if buf[cursor] != ',' {
|
||||||
return 0, errExpected("comma after object value", cursor)
|
return 0, errExpected("comma after object value", cursor)
|
||||||
}
|
}
|
||||||
|
cursor++
|
||||||
}
|
}
|
||||||
return cursor, nil
|
return cursor, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue