1 回答

TA贡献1818条经验 获得超11个赞
unmarshal into []map[string]map[string]*dynamodb.AttributeValue{}thenCapacity和 Energykey 都 unmarshal as dynamodb.AttributeValue。
因此,您可以使用外部映射的类型值,map[string]*dynamodb.AttributeValue如ExpressionAttributeValuesUpdateItemInputUpdateItem
package main
import (
"encoding/json"
"fmt"
"github.com/aws/aws-sdk-go/service/dynamodb"
)
func main() {
data := []byte(`[
{
"M": {
"Capacity": {
"S": "7"
},
"Energy": {
"S": "A+"
}
}
},
{
"M": {
"Capacity": {
"S": "7"
},
"Energy": {
"S": "A++"
}
}
},
{
"M": {
"Capacity": {
"S": "7"
},
"Energy": {
"S": "A+++"
}
}
}
]`)
d := []map[string]map[string]*dynamodb.AttributeValue{}
json.Unmarshal(data, &d)
for _, mp := range d {
expressionAttributeValues := mp["M"]
// you can use expressionAttributeValues as ExpressionAttributeValues in UpdateItemInput to UpdateItem
capacity := expressionAttributeValues["Capacity"]
energy := expressionAttributeValues["Energy"]
fmt.Printf("%+v", capacity)
fmt.Printf("%+v", energy)
}
}
- 1 回答
- 0 关注
- 111 浏览
添加回答
举报