【以下的问题经过翻译处理】 你好,我有一个包含代码的jsp(来自https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ScanJavaDocumentAPI.html):
‘’‘
<%@ page import="com.amazonaws.services.dynamodbv2.AmazonDynamoDB" %>
<%@ page import="com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder" %>
<%@ page import="com.amazonaws.services.dynamodbv2.document.DynamoDB" %>
<%@ page import="com.amazonaws.services.dynamodbv2.document.Item" %>
<%@ page import="com.amazonaws.services.dynamodbv2.document.ItemCollection" %>
<%@ page import="com.amazonaws.services.dynamodbv2.document.ScanOutcome" %>
<%@ page import="com.amazonaws.services.dynamodbv2.document.Table" %>
<%@ page import="com.amazonaws.services.dynamodbv2.model.AttributeValue" %>
<%@ page import="com.amazonaws.services.dynamodbv2.model.ScanRequest" %>
<%@ page import="com.amazonaws.services.dynamodbv2.model.ScanResult" %>
...
<%
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
DynamoDB dynamoDB = new DynamoDB(client);
String tableName = "TicketsWalletUsersDev";
// Table table = dynamoDB.getTable(tableName);
Map<String, AttributeValue> lastKeyEvaluated = null;
do {
ScanRequest scanRequest = new ScanRequest()
.withTableName(tableName)
.withLimit(10)
.withExclusiveStartKey(lastKeyEvaluated);
ScanResult result = client.scan(scanRequest);
for (Map<String, AttributeValue> item : result.getItems()){
System.out.println(item.toJSONPretty());
}
lastKeyEvaluated = result.getLastEvaluatedKey();
} while (lastKeyEvaluated != null);
%>
’‘’
它给出了以下错误:
The method toJSONPretty() is undefined for the type Map<String,AttributeValue>
我想要包含真正JSON而不是从item.toString()返回的字符串,如下所示:
{addresses={M: {mobile+75@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1583142338893,}, verified={BOOL: true}},}, federico+11@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1581332986414,}, verified={BOOL: true}},}, federico+signup3@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1581330211793,}, verified={BOOL: true}},}, federico+33@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1581330013122,}, verified={BOOL: true}},}, mobile@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1583162677615,}, verified={BOOL: true}},}, federico+12@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1581333042026,}, verified={BOOL: true}},}, federico+2@nearit.com={M: {requestId={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6_1581332941950,}, verified={BOOL: true}},}},}, created={S: 2020-02-05T10:40:17.887Z,}, userName={S: 909b1963-0ed4-4ac1-9b71-846239ed5bf6,}}
谢谢