慕虎7371278
您的 JSON 应如下所示{ "word 1": "meaning 1", "word 2": "meaning 2"}为了实现这一点,您可以使用类似的东西func fixJson(s string) string { s = strings.Replace(s, "{", "", -1) s = strings.Replace(s, "}", "", -1) return "{" + s + "}"}完整代码package mainimport ( "encoding/json" "strings" "fmt" "log")func fixJson(s string) string { s = strings.Replace(s, "{", "", -1) s = strings.Replace(s, "}", "", -1) return "{" + s + "}"}func main() { var words map[string]string var text = `{ {"word 1": "meaning 1"}, {"word 2": "meaning 2"} }` var jsonText = []byte(fixJson(text)) err := json.Unmarshal(jsonText, &words) if err != nil { log.Fatal(err) } fmt.Println(words)}