package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
)
func HttpGet(url string)(errCode int, result map[string]interface{}){
resp, err := http.Get(url)
if err != nil{
return 500, map[string]interface{}{
"state":err.Error(),
};
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
json.Unmarshal(body, &result)
return 200, result
}
func main(){
_ , body := HttpGet( "http://timor.tech/api/holiday/info/" + time.Now().Format("2006-01-02"))
cc := body["holiday"]
aa := cc.(map[string]interface{})
fmt.Print(aa, aa["holiday"])
}
Go interfacer转为map
猜你喜欢
转载自blog.csdn.net/zhizhengguan/article/details/104036587
今日推荐
周排行