我正在尝试从此页面打印数据:https://www.rolimons.com/api/activity这是它的外观:{"success":true,"activities":[[1624720645,1,6815676017,1080,1047,563399],[1624720637,1,6807138720,915,893,563398],[1624720633,1,6803395856,683,687,563397],[1624720633,1,2409285794,44853,44867,563396],[1624720623,1,71484026,2172,2114,563395],[1624720613,1,9254254,6620,6632,563394],[1624720611,1,124472052,1054,1048,563393],[1624720581,1,6803403781,671,653,563392],[1624720578,1,44113968,972,980,563391],[1624720527,1,332772333,2274,2264,563390]],"activities_count":10}我用 https://mholt.github.io/json-to-go/ 得到:type data struct { Success bool `json:"success"` Activities [][]interface{} `json:"activities"` ActivitiesCount int `json:"activities_count"`}这是我的代码: resp, err := http.Get("https://www.rolimons.com/api/activity") if err != nil { panic(err) } defer resp.Body.Close() var data *data error := json.NewDecoder(resp.Body).Decode(&data) if error != nil { panic(error) } println(data.Activities)但它给了我这个:[11/13]0xc0002bc000但我想让它打印第4和第5个值,例如:{"success":true,"activities":[[1624720645,1,6815676017,1080,1047,563399]将:1080,1047
1 回答
喵喵时光机
TA贡献1846条经验 获得超7个赞
正如您在此示例中所看到的,您可以使用 来打印该切片的数据。fmt.Printf("%+v\n", data.Activities)
若要仅打印所需的单元格,请使用索引对其进行寻址。
您可以使用方括号对切片索引进行寻址,如下所示:访问第一个嵌套切片的第 5 个元素。[]
data.Activities[0][4]
- 1 回答
- 0 关注
- 70 浏览
添加回答
举报
0/150
提交
取消