简体   繁体   English

在JAVA Restful API中从Couchbase DB获取JSON数据时出错

[英]Error on getting JSON data from Couchbase DB in JAVA Restful API

Error on getting JSON data from Couchbase DB in JAVA Restful API. 在JAVA Restful API中从Couchbase DB获取JSON数据时出错。

I am trying to retrieve JSON data from Couchbase DB and return it through an API. 我正在尝试从Couchbase DB检索JSON数据并通过API返回它。

Error : 错误:

"HTTP Status 500 - java.lang.ClassCastException: java.lang.String cannot be cast to com.couchbase.client.java.document.JsonDocument" “ HTTP状态500-java.lang.ClassCastException:java.lang.String无法转换为com.couchbase.client.java.document.JsonDocument”

Code: 码:

@Override
    public JsonDocument getProduct(String productId)
            throws URISyntaxException, IOException, InterruptedException, Exception {
        JsonDocument response = null;
        CouchbaseConnectionManager couchbaseConnectionManager = new CouchbaseConnectionManager();
        response = (JsonDocument) couchbaseConnectionManager.getCouchbaseClient().get(productId);
        return response;
    }

Could you please help. 能否请你帮忙。

Thanks 谢谢

Looks like the API returns a string and you are casting to a JsonDocument. 看起来该API返回了字符串,并且您正在强制转换为JsonDocument。 You could take the return as a string and then use org.json or other Json helpers to convert to JSON 您可以将返回值作为字符串,然后使用org.json或其他Json帮助器转换为JSON

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

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