我正在尝试从网络读取 JSON 数据,但该代码返回空结果。我不确定我在这里做错了什么。package mainimport "os"import "fmt"import "net/http"import "io/ioutil"import "encoding/json"type Tracks struct { Toptracks []Toptracks_info}type Toptracks_info struct { Track []Track_info Attr []Attr_info}type Track_info struct { Name string Duration string Listeners string Mbid string Url string Streamable []Streamable_info Artist []Artist_info Attr []Track_attr_info}type Attr_info struct { Country string Page string PerPage string TotalPages string Total string}type Streamable_info struct { Text string Fulltrack string}type Artist_info struct { Name string Mbid string Url string}type Track_attr_info struct { Rank string}func get_content() { // json data url := "http://ws.audioscrobbler.com/2.0/?method=geo.gettoptracks&api_key=c1572082105bd40d247836b5c1819623&format=json&country=Netherlands" res, err := http.Get(url) if err != nil { panic(err.Error()) } body, err := ioutil.ReadAll(res.Body) if err != nil { panic(err.Error()) } var data Tracks json.Unmarshal(body, &data) fmt.Printf("Results: %v\n", data) os.Exit(0)}func main() { get_content()}
3 回答
- 3 回答
- 0 关注
- 260 浏览
添加回答
举报
0/150
提交
取消