我无法解组一个相当简单的数据结构:
"video_lite": { "id": 1573, "name": "Blade Runner (Movie)" }
这是我的代码不起作用:
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/dynamodb/dynamodbattribute"
)
type Video struct {
video_lite struct {
name string
id int
}
}
func check(err error) {
if err != nil {
panic(err.Error())
}
}
func main() {
svc := dynamodb.New(session.New())
input := &dynamodb.GetItemInput{
Key: map[string]*dynamodb.AttributeValue{"uuid": {S: aws.String("d610e853-5222-462c-9bb3-26ff5aa86e9d")}},
ProjectionExpression: aws.String("video_lite"),
TableName: aws.String("staging_video_ingestion"),
}
result, err := svc.GetItem(input)
check(err)
fmt.Printf("%+v\n", result.Item)
var t Video
err = dynamodbattribute.UnmarshalMap(result.Item, &t)
check(err)
fmt.Printf("%+v\n", t)
}
输出如下所示:
map[video_lite:{
M: {
id: {
N: "1573"
},
name: {
S: "Bladerunner (Movie)"
}
}
}]
{video_lite:{name: id:0}}
为什么UnmarshalMap不起作用?