LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Represents JSON data structure using native Go types: booleans, floats, | 5 // Represents JSON data structure using native Go types: booleans, floats, |
6 // strings, arrays, and maps. | 6 // strings, arrays, and maps. |
7 | 7 |
8 package json | 8 package json |
9 | 9 |
10 import ( | 10 import ( |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 if err != nil { | 610 if err != nil { |
611 d.error(err) | 611 d.error(err) |
612 } | 612 } |
613 return | 613 return |
614 } | 614 } |
615 v = pv | 615 v = pv |
616 | 616 |
617 switch c := item[0]; c { | 617 switch c := item[0]; c { |
618 case 'n': // null | 618 case 'n': // null |
619 switch v.Kind() { | 619 switch v.Kind() { |
620 default: | |
621 d.saveError(&UnmarshalTypeError{"null", v.Type()}) | |
622 case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice: | 620 case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice: |
623 v.Set(reflect.Zero(v.Type())) | 621 v.Set(reflect.Zero(v.Type())) |
624 » » } | 622 » » » // otherwise, ignore null for primitives/string |
625 | 623 » » } |
626 case 't', 'f': // true, false | 624 case 't', 'f': // true, false |
627 value := c == 't' | 625 value := c == 't' |
628 switch v.Kind() { | 626 switch v.Kind() { |
629 default: | 627 default: |
630 if fromQuoted { | 628 if fromQuoted { |
631 d.saveError(fmt.Errorf("json: invalid use of ,st
ring struct tag, trying to unmarshal %q into %v", item, v.Type())) | 629 d.saveError(fmt.Errorf("json: invalid use of ,st
ring struct tag, trying to unmarshal %q into %v", item, v.Type())) |
632 } else { | 630 } else { |
633 d.saveError(&UnmarshalTypeError{"bool", v.Type()
}) | 631 d.saveError(&UnmarshalTypeError{"bool", v.Type()
}) |
634 } | 632 } |
635 case reflect.Bool: | 633 case reflect.Bool: |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 | 979 |
982 // Coerce to well-formed UTF-8. | 980 // Coerce to well-formed UTF-8. |
983 default: | 981 default: |
984 rr, size := utf8.DecodeRune(s[r:]) | 982 rr, size := utf8.DecodeRune(s[r:]) |
985 r += size | 983 r += size |
986 w += utf8.EncodeRune(b[w:], rr) | 984 w += utf8.EncodeRune(b[w:], rr) |
987 } | 985 } |
988 } | 986 } |
989 return b[0:w], true | 987 return b[0:w], true |
990 } | 988 } |
LEFT | RIGHT |