我有以下代碼,我想遍歷所有元素或訪問一個(gè)元素,birds["eagle"["quote"][2]但我無法弄清楚package mainimport ( "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)) }}
不能使用“encoding/json”覆蓋鷹(類型接口 {})
炎炎設(shè)計(jì)
2023-06-12 14:36:13