。then接受字符串

问题描述 投票:0回答:1

当前我的代码如下:

client.sendAsync(request, BodyHandlers.ofString())
            .thenApply(HttpResponse::body)
            .thenAccept(System.out::println)
            .join()

。thenAccept(System.out :: println)行从last.fm打印JSON查询响应。

我试图找出要替换System.out :: println的内容,而不是将响应保存到String中,然后我可以迭代该字符串以定义Album和Track对象的各个部分。任何帮助将不胜感激。

java json completable-future
1个回答
0
投票

具体解决方案在很大程度上取决于HttpResponse::body的返回类型。假设返回的对象是String,则有多种选择方式。一个可能是:

© www.soinside.com 2019 - 2024. All rights reserved.