1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package xvdoc
- import (
- "bytes"
- "encoding/json"
- )
- type cellImage struct {
- x, y int
- path string
- name string
- ext string
- format JSONMap
- }
- func (s *cellImage) UnmarshalJSON(src []byte) (err error) {
- dec := json.NewDecoder(bytes.NewReader(src))
- var t json.Token
- for dec.More() && err == nil {
- if t, err = dec.Token(); err == nil {
- if _, check := t.(json.Delim); !check {
- switch t.(string) {
- case "x":
- err = dec.Decode(&s.x)
- case "y":
- err = dec.Decode(&s.y)
- case "path":
- err = dec.Decode(&s.path)
- case "format":
- if err = dec.Decode(&s.format); err != nil {
- s.format = nil
- }
- case "name":
- err = dec.Decode(&s.name)
- case "ext":
- err = dec.Decode(&s.ext)
- default:
- err = dec.Decode(new(interface{}))
- }
- }
- }
- }
- return
- }
|