我正在编写一个 Java 应用程序,它通过 REST API 向在本地网络中运行的命名实体识别服务 ( deeppavlov ) 发出请求。
所以我通过以下方式请求数据:
String text = "Welcome to Moscow, John";
List<String> textList = new ArrayList<String>();
textList.add(text);
JSONObject json = new JSONObject();
json.put("x", textList);
String URL = "http://localhost:5005/model";
HttpClient client = HttpClient.newBuilder()
.version(Version.HTTP_1_1)
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(URL))
.header("accept", "application/json")
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(json.toString()))
.build();
try {
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
System.out.println(response.body());
System.out.println(response.body().getClass());
} catch (IOException | InterruptedException e) {
}
结果我得到:
[[["欢迎","to","莫斯科",",","约翰"],["O","O","B-GPE","O","B-PERSON"]] ] 类 java.lang.String
它是一个字符串,我不知道如何将其转换为对象、数组、映射或列表以进行迭代。请帮忙。