[英]Convert dynamodb json to normal json using C#
我正在尝试使用 C# 将 dynamodb json 转换为普通 json,实际上对于对象类型 M 我无法实现转换仍然得到如下结果
{
"RecordDetails": {
"firstName": {
"Value": “32432-ere”,
"Type": 0
},
"lastName": {
"Value": "32432-ere",
"Type": 0
},
"contactInformation": {
"addressLine1": {
"Value": "10 Downing st",
"Type": 0
},
"addressLine2": {
"Value": "",
"Type": 0
},
"city": {
"Value": "Portand",
"Type": 0
},
"phone": {
"Value": "555-555-5555",
"Type": 0
},
"email": {
"Value": "jdoe@abc.com”,
"Type": 0
}
},
"employer": {
“Id”: {
"Value": “test:1473969",
"Type": 0
}
},
"middleName": {
"Value": "A",
"Type": 0
},
"id": {
"Value": "637934995361318864",
"Type": 0
},
"title": {
"Value": "Dr.",
"Type": 0
},
"userId": {
"Value": “ererew-2332432”,
"Type": 0
},
"earnedDegrees": {
"Value": "MD.",
"Type": 0
}
},
"ValidationStatus": {
"Value": "Passed",
"Type": 0
},
"TypeOfRecord": {
"Value": “test”,
"Type": 0
},
"TenantCode": {
"Value": “demo2”,
"Type": 0
},
"Action": {
"Value": "create",
"Type": 0
},
"TenantHostName": {
"Value": “t1.demo.com",
"Type": 0
},
"ImportJobId": {
"Value": “erewre7777”-322h23h,
"Type": 0
},
"ValidationMessage": {
"Value": "No Errors",
"Type": 0
},
"ProcessingResult": {
"Value": "Fail",
"Type": 0
},
"ProcessedAt": {
"Value": "2022-07-20T10:07:43.650Z",
"Type": 0
},
"RecordId": {
"Value": “dfdsf-3242-sdfds”,
"Type": 0
},
"ApiResponse": {
"errors": {
"Entries": [
{
"code": {
"Value": "-1",
"Type": 1
},
"internalErrorMessage": {
"Value": "",
"Type": 0
},
"links": {
"about": {
"Value": "",
"Type": 0
},
"help": {
"Value": "",
"Type": 0
}
},
"detail": {
"Entries": [
{
"Value": "23505: duplicate key value violates ",
"Type": 0
}
]
},
"source": {
"Value": “test Service",
"Type": 0
},
"incidentId": {},
"status": {
"Value": "500",
"Type": 1
}
}
]
}
} }
实际上是使用Document.FromAttributeMap()来获得上述结果,但我仍然需要让它看起来像一个普通的 json 值,比如
{
"RecordDetails": {
"firstName": “32432-ere”,
"lastName": "32432-ere",
"contactInformation": {
"addressLine1": "10 Downing st",
"addressLine2": “”,
"city": "Portand",
"phone": "555-555-5555",
"email": "jdoe@abc.com”
},
"employer": {
“Id”: “test:1473969"
},
"middleName": "A",
"id": "637934995361318864",
"title": "Dr.",
"userId": “ererew-2332432”,
"earnedDegrees": "MD.", },
"ValidationStatus":"Passed",
"TypeOfRecord": “test”,
"TenantCode": “demo2”,
"Action": "create",
"TenantHostName": “t1.demo.com",
"ImportJobId": “erewre7777-322h23h”,
"ValidationMessage": "No Errors",
"ProcessingResult": "Fail",
"ProcessedAt": "2022-07-20T10:07:43.650Z",
"RecordId":“dfdsf-3242-sdfds”,
"ApiResponse": {
"errors": {
"Entries": [
{
"code": "-1",
"internalErrorMessage": “”,
"links": {
"about": “”,
"help”:”” },
"detail": {
"Entries": [
{
"23505: duplicate key value violates "
}
]
},
"source": “test Service",
"incidentId": {},
"status": “500”
}
]
}
} }
任何人都可以通过建议一些 nuget 包或通过一些手动过程来帮助我实现这一点,尝试了很多仍然无法实现这一点,抱歉,如果这是一个重复的问题。
提前致谢
您应该使用ToJsonPretty
扩展方法从文档对象中获取漂亮的 JSON。
Document document = Document.FromAttributeMap(...);
string jsonString = document.ToJsonPretty(); <--- This is what you need
对于此消息,您需要Amazon.DynamoDBv2.DocumentModel
命名空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.