0
我無法來解讀一個相當簡單的數據結構:如何將dynamodb結果解析爲一個整數?
"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不工作?
試過'{video_lite:{名稱:{N: S:} ID:{N: S:}}}'是輸出。也嘗試下載'video_lite'並得到'{name:{N: S:} id:{N: S:}}: –
hendry