从球衣客户响应中读取个人价值

Reading individual value from jersey client response

嗨,我正在使用波纹管代码调用 API

 Client client=ClientBuilder.newClient();
 WebTarget target = client.target(dynamicEntityURL);
 String response = target.request().header("Authorization", "Bearer "+readToken.tokenMethod()
                                 .getAccess_token())
                                 .get(String.class);
System.out.println(response);

输出是:-

{"count":1,"limit":100,"totalResults":1,"hasMore":false,"items":[{"id":"B183C87E-7067-4BC9-BD9D-5AFA145532F3","name":"DynamicEntityTesting","version":"1.0","status":"PUBLISHED"}],"links":[{"rel":"self","href":"https://idcs-oda-9417f93560b94eb8a2e2a4c9aac9a3ff-t0.data.digitalassistant.oci.oc-test.com/api/v1/skills/?name=DynamicEntityTesting"},{"rel":"canonical","href":"https://idcs-oda-9417f93560b94eb8a2e2a4c9aac9a3ff-t0.data.digitalassistant.oci.oc-test.com/api/v1/skills/?name=DynamicEntityTesting"}]}

在上面的输出中我只需要id,它在items下面。我知道我可以创建 POJO 并传递它并使用 getter/setter 读取单个值。但是我将不得不创建具有所有输出参数的 POJO。我只需要 id 传递给下一个 API。我怎样才能得到 id 的值?

你可以这样做。

JsonObject response = target.request().header("Authorization", "Bearer "+readToken.tokenMethod()
                                 .getAccess_token())
                                 .get(JsonObject.class);
          JsonArray jsonArray = response.getJsonArray("items");
          System.out.println(jsonArray.getJsonObject(0).getString("id"));