简体   繁体   English

aws dynamo db 在响应中删除数据类型

[英]aws dynamo db get rid of datatype in response

I have a sample table in AWS Dynamo DB.我在 AWS Dynamo DB 中有一个示例表。

When I am trying to read items from it by using Lambda, in the response am seeing additional data types from dynamo db.当我尝试使用 Lambda 从中读取项目时,在响应中我看到了来自 dynamo db 的其他数据类型。

is there any way we can avoid them ?有什么办法可以避免它们吗?

 [{
"year": {
  **"S":** "2018"
},
"state": {
  **"S"**: "NSW"
}},{"year": {
  **"S":** "2017"
},
"state": {
  **"S"**: "NSW"
} }]    

I don't want to have "S" in response.我不想有“S”作为回应。

I would like to have response like this.我想得到这样的回应。

{"year": "2018"} {“年”:“2018”}

This will be possible ?这有可能吗?

If you are using NodeJS, you can use the AWS DynamoDB DocumentClient SDK , instead of the core SDK to do the queries.如果您使用 NodeJS,则可以使用AWS DynamoDB DocumentClient SDK而不是核心 SDK 来执行查询。 This will simplify both querying and the results.这将简化查询和结果。

However for other languages that doesn't have the Document Client SDK, you need to write your own wrapper to parse and filter the types from query results.但是,对于没有 Document Client SDK 的其他语言,您需要编写自己的包装器来解析和过滤查询结果中的类型。

Yes you can use the following code to convert in to readable json format without unwanted datatypes Document doc = Document.FromAttributeMap(item);是的,您可以使用以下代码转换为可读的 json 格式,而不需要不需要的数据类型 Document doc = Document.FromAttributeMap(item); string documentresp = doc.ToJson();字符串 documentresp = doc.ToJson();

Just change the SDK for Dynamo DB Use aws.DynamoDB.DocumentClient() instead of AWS.DynamoDB();只需更改 Dynamo DB 的 SDK 使用aws.DynamoDB.DocumentClient()而不是AWS.DynamoDB(); . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM