Golang:Unmarshal JSON对象导致空映射

Golang:Unmarshal JSON对象导致空映射,json,go,Json,Go,我一直在尝试解组json对象。我没有得到任何错误,但我得到一个空地图之后。我是新来的,所以我仍在努力思考一些语言结构 下面是我的数据源的样子 { "animationStates": { "idle": { "numFrames": 4, "frames": [ { "frame": {"x":43,"y":106,"w":12,"h":15},

我一直在尝试解组json对象。我没有得到任何错误,但我得到一个空地图之后。我是新来的,所以我仍在努力思考一些语言结构

下面是我的数据源的样子

{ 
    "animationStates": {
        "idle": {
            "numFrames": 4,
            "frames": [
                {
                    "frame": {"x":43,"y":106,"w":12,"h":15},
                    "rotated": false
                },
                {
                    "frame": {"x":1,"y":143,"w":12,"h":14},
                    "rotated": false
                },
                {
                    "frame": {"x":71,"y":132,"w":12,"h":14},
                    "rotated": false
                },
                {
                    "frame": {"x":15,"y":126,"w":12,"h":15},
                    "rotated": true 
                }
            ]
        },
        "run": {
            "numFrames": 10,
            "frames": [
                {
                    "frame": {"x":73,"y":82,"w":12,"h":15},
                    "rotated": false
                },
                {
                    "frame": {"x":29,"y":125,"w":12,"h":15},
                    "rotated": false
                },
                {
                    "frame": {"x":33,"y":36,"w":12,"h":16},
                    "rotated": false
                },
                {
                    "frame": {"x":1,"y":107,"w":12,"h":16},
                    "rotated": false
                },
                {
                    "frame": {"x":1,"y":89,"w":12,"h":16},
                    "rotated": false
                },
                {
                    "frame": {"x":17,"y":54,"w":12,"h":16},
                    "rotated": false
                },
                {
                    "frame": {"x":1,"y":125,"w":12,"h":16},
                    "rotated": false
                }
                {
                    "frame": {"x":15,"y":143,"w":12,"h":14},
                    "rotated": false
                },
                {
                    "frame": {"x":29,"y":142,"w":12,"h":14},
                    "rotated": false
                },
                {
                    "frame": {"x":72,"y":99,"w":12,"h":15},
                    "rotated": false
                }
            ]
        },
        "roll": {
            "numFrames": 5,
            "frames": [
                {
                    "frame": {"x":71,"y":116,"w":12,"h":14},
                    "rotated": false
                },
                {
                    "frame": {"x":71,"y":148,"w":12,"h":10},
                    "rotated": false
                },
                {
                    "frame": {"x":73,"y":47,"w":12,"h":15},
                    "rotated": false
                },
                {
                    "frame": {"x":57,"y":147,"w":12,"h":11},
                    "rotated": false
                },
                {
                    "frame": {"x":29,"y":108,"w":12,"h":15},
                    "rotated": false
                }
            ]
        },
        "jump": {
            "numFrames": 1,
            "frames": [
                {
                    "frame": {"x":45,"y":54,"w":12,"h":16},
                    "rotated": false
                }
            ]
        },
        "fall": {
            "numFrames": 1,
            "frames": [
                {
                    "frame": {"x":29,"y":90,"w":12,"h":16},
                    "rotated": false
                }
            ]
        },
        "shoot": {
            "numFrames": 5,
            "frames": [
                {
                    "frame": {"x":37,"y":1,"w":14,"h":15},
                    "rotated": false
                },
                {
                    "frame": {"x":17,"y":37,"w":14,"h":15},
                    "rotated": false
                },
                {
                    "frame": {"x":1,"y":37,"w":14,"h":16},
                    "rotated": false
                },
                {
                    "frame": {"x":19,"y":19,"w":14,"h":15},
                    "rotated": false
                },
                {
                    "frame": {"x":1,"y":55,"w":14,"h":15},
                    "rotated": false
                }
            ]
        }
    }
}
这是我用来解组的代码

package main

import (
    "encoding/json"
    "io/ioutil"
)

type AnimationFrame struct {
    Frame struct {
        X int `json:"x"`
        Y int `json:"y"`
        W int `json:"w"`
        H int `json:"h"`
    } `json:"frame"`
    Rotated bool `json:"rotated"`
}

type Animation struct {
    NumFrames int `json:"numFrames"`
    Frames []AnimationFrame `json:"frames"` 
} 

type StateList struct {
    Actions map[string]Animation `json:"animationStates"`
}

func NewAnimation (file string) *StateList {
    list := make(map[string]Animation)
    s := &StateList{list}
    buff, err := ioutil.ReadFile(file)
    check(err)
    json.Unmarshal([]byte(buff), &s)
    return s 
}

func check (e error) {
    if e != nil {
        panic(e)
    }
}

有人知道我做错了什么吗?谢谢。

检查并处理从
json.Unmarshal([]字节(buff),&s)
返回的错误。您将发现偏移量1685处的数组元素后面有一个无效字符“{”


谢谢!我不知道如何检查和处理这个解组。