Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用数组中包含的[int]字符串映射对JSON进行解组_Json_Go - Fatal编程技术网

使用数组中包含的[int]字符串映射对JSON进行解组

使用数组中包含的[int]字符串映射对JSON进行解组,json,go,Json,Go,我试图将下面的JSON解组为一个结构,但在那里我无法用[[int,string]]转换值字段的内容 这就是我到目前为止所做的: type Response struct { Metric struct { Name string `json:"name,omitempty"` Appname string `json:"appname,omitempty"` } `json:"metr

我试图将下面的JSON解组为一个结构,但在那里我无法用[[int,string]]转换值字段的内容 这就是我到目前为止所做的:

type Response struct {
            Metric struct {
                Name string `json:"name,omitempty"`
                Appname string `json:"appname,omitempty"`
            } `json:"metric,omitempty"`
            Values []map[int]string `json:"values,omitempty"`
}
JSON文件:

{
   "metric":{
      "name":"x444",
      "appname":"cc-14-471s6"
   },
   "values":[
      [
         1508315264,
         "0.0012116165566900816"
      ],
      [
         1508315274,
         "0.0011871631158857396"
      ]
   ]
}

您显示的数据应解组到:

type Response struct {
            Metric struct {
                Name string `json:"name,omitempty"`
                Appname string `json:"appname,omitempty"`
            } `json:"metric,omitempty"`
            Values [][]interface{} `json:"values,omitempty"`
}
如果要将其传输到映射实现json.Unmarshaller接口-

您可以选择以下内容:

type Item struct {
    Key int
    Val string
}
func(item *Item) UnmarshalJSON([]byte) error {
    // TODO: implement 
}

type Response struct {
            Metric struct {
                Name string `json:"name,omitempty"`
                Appname string `json:"appname,omitempty"`
            } `json:"metric,omitempty"`
            Values []Item  `json:"values,omitempty"`
}