json: Properly handle nil slices.

Marshal nil slices as null and parse null value as a nil slice.
Fixes #2278.

R=rsc
CC=golang-dev
https://golang.org/cl/5257053
This commit is contained in:
Alexander Reece 2011-10-31 13:59:23 -04:00 committed by Russ Cox
parent 288dacd016
commit 48c75c5f9c
4 changed files with 18 additions and 10 deletions

View file

@ -588,7 +588,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value) {
switch v.Kind() {
default:
d.saveError(&UnmarshalTypeError{"null", v.Type()})
case reflect.Interface, reflect.Ptr, reflect.Map:
case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice:
v.Set(reflect.Zero(v.Type()))
}