总结问题
我制作了一些从 toggl api 接收数据的应用程序。我尝试将 []byte 响应数据保存在 Go 中的数组列表中,以便稍后修改数据。我想知道如何将此响应 []byte json 样式数据转换和存储为数组列表。
显示一些代码
main.go
type togglData struct {
}
func GetTogglReports() []byte {
//some code
resp, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
return data
}
func makeSurveyText() {
// I want to save []byte data GetTogglReports() in array list here.
var togglData []togglData
}
数据是这样的:
{
"total_grand":36004000,
"total_billable":14400000,
"total_currencies":[{"currency":"EUR","amount":40}],
"data": [
{
"id":193009951,
"title":{"project":"Toggl Development","client":null},
"time":14400000,
"total_currencies":[{"currency":"EUR","amount":0}],
"items":[
{
"title":{"time_entry":"Hard work"},
"time":14400000,
"cur":"EUR",
"sum":0,
"rate":50
}
]
},{
"id":null,
"title":{"project":null,"client":null},
"time":7204000,
"total_currencies":[],
"items":[
{
"title":{"time_entry":"No title yet"},
"time":1000,
"cur":"EUR",
"sum":0,
"rate":50
}
]
}
]
}
至尊宝的传说
相关分类