类型Map<String,AttributeValue>没有定义toJSONPretty()方法。

0

【以下的问题经过翻译处理】 你好,我有一个包含代码的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,}}

谢谢

profile picture
专家
已提问 1 年前51 查看次数
1 回答
0

【以下的回答经过翻译处理】 的代码中没有Map<String, AttributeValue>的toJsonPretty()方法。

要获取JSON,您应该先从表中获取Item。您可以参考此处指定可选参数的代码示例:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/JavaDocumentAPIItemCRUD.html#JavaDocumentAPIGetItem

profile picture
专家
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则