如何将json文件读入Map [关闭]

I have a json file like this - data.json

{
    "data1" : {
        "tag" : "some_tag1",
        "info" : "some_info1",
    },
     "data2" : {
        "tag" : "some_tag2",
        "info" : "some_info2",
    }
}

I have a struct like below

type someStruct struct {
    tag    string `json:"tag"`
    info   string `json:"info"`

}

I am trying to read json file into below map

errorJSON    map[string]someStruct

Below is my code

jsonParser := json.NewDecoder(data.json)
err := jsonParser.Decode(&errorJSON)

But I am getting a error

json.UnmarshalTypeError

What am I doing wrong

There's a problem with the data. It is not valid JSON as it has trailing commas.

Try with this:

{
    "data1" : {
        "tag" : "some_tag1",
        "info" : "some_info1"
    },
     "data2" : {
        "tag" : "some_tag2",
        "info" : "some_info2"
    }
}

You must uppercase someStruct fields and json must valid format.

type someStruct struct {
    Tag  string `json:"tag"`
    Info string `json:"info"`
}

Your example json has extra commas - removed

The data structure is a pair of your someStruct with keys, so needs to be a map

uppercase the json struct fields

Here is a working example based on your code

package main

import (
    "encoding/json"
    "fmt"
)

type someStruct struct {
    Tag  string `json:"tag"`
    Info string `json:"info"`
}

func main() {
    buf := `{
    "data1" : {
        "tag" : "some_tag1",
        "info" : "some_info1"
    },
     "data2" : {
        "tag" : "some_tag2",
        "info" : "some_info2"
    }
}`

    dat := make(map[string]someStruct)

    if err := json.Unmarshal([]byte(buf), &dat); err != nil {
        panic(err)
    }
    fmt.Println("Hello, playground", dat)
}

playground https://play.golang.org/p/ZGuCcGI3vA6