更新时间:2021-10-17 23:18:29
此处的数据类型是关键。 mdi
实际上不是地图,而是 interface {}
,它可以是任何东西-地图,字符串,一个int。您需要首先将其声明为具有预期键/值类型的映射,或者执行 JSON和Go 。
The data type here was the key. mdi
was not actually a map, but an interface{}
, which could be anything - a map, a string, an int. You need to assert it to a map with expected key/value types first, or do the awkward case
switch outlined in JSON and Go.
mdi, err := page.Metadata()
md, ok := mdi.(map[string]interface{})
fmt.Println(md["title"])