我有 map 中的数据,我想通过键索引到 map 中以获得一个值.
mdi, err := page.Metadata()
fmt.Println(mdi["title"])
但是,我一直收到错误消息invalid operation: mdi["title"] (type interface {} does not support indexing)
.我很困惑,因为数据是一张 map ,我应该能够对其进行索引以获得值.如果类型不清楚,我还try 将值转换为字符串:
title, ok := mdi["title"].(string)
checkOk(ok)
fmt.Println(title)
但是,我收到了相同的错误消息.我做错了什么?