我正在尝试读取一个 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)我如何使这项工作?
1 回答
ibeautiful
TA贡献1993条经验 获得超5个赞
根据您的问题,我不确定您要做什么,但是您不能更改函数的返回类型吗?
func GetConfigMap(name string) map[string]interface{} {
valueMap := configurations[name]
return valueMap.(map[string]interface{})
}
- 1 回答
- 0 关注
- 160 浏览
添加回答
举报
0/150
提交
取消