Mat*_*att 2 c# amazon-web-services amazon-dynamodb
在我的 C# lambda 中,我从 DynamoDB 中检索了一个项目。它作为Dictionary<string, AttributeValue>. 有没有一种将其序列化为 JSON 的好方法?
AttributeValue 类公开了一组属性来检索不同类型的值。如果你做一个简单的序列化,这些属性中的每一个都会出现在 JSON 中,其中大部分都是空的,并且会形成一个非常混乱的对象。
我希望它识别地图并将其转换为 JSON 对象,识别列表并将其转换为 JSON 列表。基本上,我想要 Item 代表的对象。
小智 5
您可以使用 C# 中的替代方法通过 DocumentModel 连接到 DynamoDB。这个 DocumentModel 有一个 ToJson() 函数。
Table table = Table.LoadTable(client, "yourtable");
Document document = table.GetItem(123);
string strJSON = document.ToJson();
Run Code Online (Sandbox Code Playgroud)