UnmarshalJSON satisfies the json.Unmarshaler interface.
(text []byte)
| 40 | |
| 41 | // UnmarshalJSON satisfies the json.Unmarshaler interface. |
| 42 | func (m *Map) UnmarshalJSON(text []byte) error { |
| 43 | // UnmarshalJSON takes only valid json, we can take advantage of this |
| 44 | // to see if the first character is either '{' for an object or 'n' |
| 45 | // for null. |
| 46 | v, err := ValueType(text) |
| 47 | if err != nil { |
| 48 | return err |
| 49 | } |
| 50 | switch v { |
| 51 | case Null: |
| 52 | return nil |
| 53 | case Object: |
| 54 | *m = text |
| 55 | return nil |
| 56 | default: |
| 57 | return ErrNotMap |
| 58 | } |
| 59 | } |