Amazon web services Golang DynamoDB解组shallistofMaps返回空数组
我有一个DynamoDB产品表(id(int)、active(bool)、name(string)、price(int)),当我检索并尝试解组列表时,它返回空Amazon web services Golang DynamoDB解组shallistofMaps返回空数组,amazon-web-services,go,nosql,amazon-dynamodb,Amazon Web Services,Go,Nosql,Amazon Dynamodb,我有一个DynamoDB产品表(id(int)、active(bool)、name(string)、price(int)),当我检索并尝试解组列表时,它返回空 [{},{}] 结构: type Product struct { id int active bool name string price int } 要解组的代码如下所示: params := &dynamodb.ScanInput{ TableName: aws.String("Produc
[{},{}]
结构:
type Product struct {
id int
active bool
name string
price int }
要解组的代码如下所示:
params := &dynamodb.ScanInput{
TableName: aws.String("Products"),
}
result, err := service.Scan(params)
if err != nil {
fmt.Errorf("failed to make Query API call, %v", err)
}
var products = []Product{}
var error = dynamodbattribute.UnmarshalListOfMaps(result.Items, &products)
我做错了什么 只能取消对公共字段的签名 使用大写字母公开结构字段,并使用
json
属性将其映射到数据值:
type Product struct {
ID int `json:"id"`
Active bool `json:"active"`
Name string `json:"name"`
Price int `json:"price"`
}
OP可能应该使用
dynamodbav
而不是json
,例如:dynamodbav:“id”
,因为他们正在使用dynamodb。你救了我的命