func getLatestTxs() map[string]interface{}{} {
fmt.Println("hello")
resp, err := http.Get("http://api.etherscan.io/api?module=account&action=txlist&address=0x266ac31358d773af8278f625c4d4a35648953341&startblock=0&endblock=99999999&sort=asc&apikey=5UUVIZV5581ENPXKYWAUDGQTHI956A56MU")
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Errorf("etherscan访问失败")
}
ret := map[string]interface{}{}
json.Unmarshal(body, &ret)
if ret["status"] == 1 {
return ret["result"]
}
}
我希望在我的代码中返回 map[string]interface{}{}
。
但是我得到了编译错误:syntax error: unexpected [ after top level declaration
。
如果我将map[string]interface{}{}
更改为interface{}
,则不再有编译错误。
注意:我使用map[string]interface{}{}
是因为我想返回一个映射列表。
[]
。例如,[]map[string]interface{}
。 - mkopriva[]map[string]interface{}
,将会抛出一个错误。因为ret["result"]
是一个interface{}
。 - Himanshu