我正在尝试读取一个 json 文件,执行该操作的代码如下所示
var configurations map[string]interface{}
func GetConfigMap(name string) interface{} {
valueMap := configurations[name]
return valueMap.(map[string]interface{})
}
我正在尝试阅读地图,如下所示,
glossary := jsonreader.GetConfigMap("glossary")
fmt.Println(glossary["GlossDiv"])
json结构如下,
{ "glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
我收到一个例外,说 -
invalid operation: glossary["GlossDiv"] (type interface {} does not support indexing)
我如何使这项工作?
ibeautiful
相关分类