2
我正在嘗試向facebook REST API發出請求,並返回JSON響應。我可以在REST客戶端收集響應,因此我知道在下面的代碼中創建HttpRequest時使用的requestUrl是正確的。但是當我嘗試使用akka-http javadsl來模擬GET時,我無法理解如何從ResponseEntity中提取json。從akka http javadsl提取響應json字符串ResponseEntity
final HttpRequest request = HttpRequest.GET(requestUrl);
final Materializer materializer = ActorMaterializer.create(this.context.getActorSystem());
final CompletionStage<HttpResponse> responseFuture =
Http.get(this.context.getActorSystem()).singleRequest(request, materializer);
final HttpResponse response = responseFuture.toCompletableFuture().get();
我期待的迴應的東西如下 -
{
"data": [
{
"cpc": 9.7938056680162,
"clicks": "247",
"impressions": "15949",
"spend": 2419.07,
"date_start": "2016-06-15",
"date_stop": "2016-08-13"
}
],
"paging": {
"cursors": {
"before": "MAZDZD",
"after": "MAZDZD"
}
}
}