2 回答
TA贡献1818条经验 获得超3个赞
上面的值resp是类型*ScanOutput,其Items类型为[]map[string]*AttributeValue。
要访问update_time,您可以尝试:
updateTimes := make([]string, 0)
// Items is a slice of map of type map[string]*AttributeValue
for _, m := range resp.Items {
// m is of type map[string]*AttributeValue
timeStrPtr := *m["update_time"].N
updateTimes = append(updateTimes, *timeStrPtr)
}
updateTimes现在应该包含所有"update_time"值作为字符串。
TA贡献1839条经验 获得超15个赞
你应该使用这个dynamodbattribute包。它更便宜、更安全、更易读。
按照你的例子:
type Row struct {
CreateTime int `dynamodbav:"create_time"`
UpdateTime int `dynamodbav:"update_time"`
}
// ...
rows := make([]*Row, len(resp.Items))
if err := dynamodbattribute.Unmarshal(resp.Items, &rows); err != nil {
// handle the error
}
// access the data
for _, row := range rows {
fmt.Println(row.CreateTime, row.UpdateTime)
}
- 2 回答
- 0 关注
- 161 浏览
添加回答
举报
