forked from mirror/go-json
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++
|
||||
return cursor, nil
|
||||
}
|
||||
for ; cursor < buflen; cursor++ {
|
||||
var key interface{}
|
||||
keyCursor, err := d.setKey(buf, cursor, &key)
|
||||
for {
|
||||
k := unsafe_New(d.keyType)
|
||||
keyCursor, err := d.keyDecoder.decode(buf, cursor, k)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
cursor = keyCursor
|
||||
cursor = skipWhiteSpace(buf, cursor)
|
||||
cursor = skipWhiteSpace(buf, keyCursor)
|
||||
if buf[cursor] != ':' {
|
||||
return 0, errExpected("colon after object key", cursor)
|
||||
}
|
||||
cursor++
|
||||
if cursor >= buflen {
|
||||
return 0, errUnexpectedEndOfJSON("map", cursor)
|
||||
}
|
||||
var value interface{}
|
||||
valueCursor, err := d.setValue(buf, cursor, &value)
|
||||
v := unsafe_New(d.valueType)
|
||||
valueCursor, err := d.valueDecoder.decode(buf, cursor, v)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
mapassign(d.mapType, mapValue, unsafe.Pointer(&key), unsafe.Pointer(&value))
|
||||
mapassign(d.mapType, mapValue, k, v)
|
||||
cursor = skipWhiteSpace(buf, valueCursor)
|
||||
if buf[cursor] == '}' {
|
||||
**(**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] != ',' {
|
||||
return 0, errExpected("comma after object value", cursor)
|
||||
}
|
||||
cursor++
|
||||
}
|
||||
return cursor, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue