【发布时间】:2022-01-20 13:42:25
【问题描述】:
我正在使用查询从 DynamoDB 检索数据,并返回以下内容:
[{"serviceUserId":{"S":"123456789"},"createdDate":{"S":"11-12-2021"}}]
DynamoDB JSON 格式具有我试图通过转换为普通 JSON 格式来摆脱的类型。我曾尝试使用AWS.DynamoDB.Converter.unmarshall,但我的代码出现错误:
Argument of type 'ItemList' is not assignable to parameter of type "AttributeMap".
Index signature for type 'string' is missing in type "AttributeMap[]".
这是我的代码:
if (result.Count > 0) {
const newImage = AWS.DynamoDB.Converter.unmarshall(
result.Items
)
console.log('new Image: ' + JSON.stringify(newImage));
resolve(newImage);
} else {
console.log('No record found');
reject(err);
}
如果我删除 DynamoDB JSON 中的 [] 括号,则它会成功转换,但显然我不能在我的程序中执行此操作,因为括号存在是有原因的!
有人知道如何将我的 JSON 文件转换为unmarshall 可以接受的格式吗?
【问题讨论】:
-
result的值是多少?result.Items是什么? -
result 和 result.items 是 '[object Object]' ,当我将它字符串化时,我得到 '[{"serviceUserId":{"S":"123456789"},"createdDate":{" S":"11-12-2021"}}]'
标签: amazon-web-services amazon-dynamodb unmarshalling