java - 如何使用 azure-cosmos sdk 在 JAVA java 中将 cosmos 响应作为 JSON 数组获取
问题描述
我可以在 azure cosmos-db explore 中运行查询,如下图所示,并将响应视为 json 数组
我想使用带有 azure-cosmos SDK 的 Java 做同样的事情
下面是我的功能
public JSONArray getCosmosResponseFromSyncClient(String databaseName, String
containerName, String sqlQuery) {
try {
cosmosClient = new
CosmosClientBuilder().endpoint(cosmosURI).key(cosmosPrimaryKey).buildClient();
CosmosDatabase database = cosmosClient.getDatabase(databaseName);
CosmosContainer container = database.getContainer(containerName);
int preferredPageSize = 10;
CosmosQueryRequestOptions queryOptions = new CosmosQueryRequestOptions();
queryOptions.setQueryMetricsEnabled(true);
CosmosPagedIterable < JSONArray > responsePagedIterable = container.queryItems(sqlQuery,
queryOptions, JSONArray.class);
return cosmosQueryResponseObjectAsAJSONArray;
}finally {
cosmosClient.close();
}
}
解决方案
推荐阅读
- sql - 更新后日期格式值未从以前的格式更新为新格式
- swiftui - 如何防止 SwiftUI SegmentedControl 中的文本“弹跳”
- java - 如何在 Visual Studio Code 中安装 LWJGL3?
- r - 使用 -ply 系列重复例程在 R 中获取矩阵
- python - 我怎样才能让 BeautifulSoup 找到多个标签?
- r - 在 MGCV 包 RStudio 中使用 MRF 创建预测回归方程
- c++ - PlatformIO中外部环境变量的访问
- r - ggplot2中的geom_tile返回空白图
- java - 无响应的套接字读取缓冲区
- java - 尝试启动我的 Spring Boot 应用程序时,即使我设置了它们,我也需要谷歌凭据