【发布时间】:2014-10-02 13:19:51
【问题描述】:
我有地图中的数据,我想通过键索引到地图中以获取值。
mdi, err := page.Metadata()
fmt.Println(mdi["title"])
但是我不断收到错误消息invalid operation: mdi["title"] (type interface {} does not support indexing)。我很困惑,因为数据是一张地图,我应该能够对其进行索引以获得价值。如果类型不清楚,我还尝试将值转换为字符串:
title, ok := mdi["title"].(string)
checkOk(ok)
fmt.Println(title)
但是,我收到了相同的错误消息。我做错了什么?
【问题讨论】: