我有以下代码,我想遍历所有元素或访问一个元素,birds["eagle"["quote"][2]但我无法弄清楚
package main
import (
"fmt"
"encoding/json"
)
func main() {
birdJson := `{"birds": {"pigeon": {"quotes": "love the pigeons"}, "eagle": {"quotes": ["bird of prey", "soar like an eagle", "eagle has no fear"]}}}`
var result map[string]interface{}
json.Unmarshal([]byte(birdJson), &result)
birds := result["birds"].(map[string]interface{})
fmt.Printf("%v\n",birds)
eagle := birds["eagle"]
for key, value := range eagle {
fmt.Println(key, value.(string))
}
}
临摹微笑
相关分类