Я получаю ответ JSON от API.Я должен вернуть ответ JSON другому методу с выбранными полями
Здесь я извлекаю весь ответ JSON и помещаю его в JSONArray, который я должен вернуть в другой метод.
Как получить обаString и Long возвращают поля и помещают его в массив JSON и возвращают его другому методу
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("/2.0/clusters/list");
request.addHeader("Authorization", "bearerToken");
request.addHeader("cache-control", "no-cache");
HttpResponse response = client.execute(request);
System.out.println("Response Code:" +
response.getStatusLine().getStatusCode());
String json = EntityUtils.toString(response.getEntity());
System.out.println("Gather Details\n");
JSONObject cluster = new JSONObject(json);
JSONArray clusterJsonArray = cluster.getJSONArray("clusters");
for (int i = 0; i < clusterJsonArray.length(); i++) {
JSONObject iteratingObj = array.getJSONObject(i);
String id = iteratingObj.get("id").toString();
String time = iteratingObj.get("time").toString();
System.out.println("Id:" + id + "time:" + time + "\n");
List<String> strList = new ArrayList<>();
for (int p = 0; p < clusterJsonArray.length(); p++) {
strList.add(clusterJsonArray.getJSONObject(p).getString("id"));
strList.add(clusterJsonArray.getJSONObject(p).getString("time"));
}
System.out.println("Arr:" + strList);
if (response.getStatusLine().getStatusCode() != 200) {
System.out.println("Failed HTTPresponse" + response.getStatusLine().getStatusCode() + "" + json);
}
}
Помогите мне отправить ответ с выбранными полями другому методу, в котором этот JSONarray должен принимать как String, так и Longзначений и сохраните его в одной переменной JSONArray.
Вот входящий JSON:
"clusters": [
{ "id": "0411-0089ki", "driver": { }, "start_timestamp": 1568952332573, },
Здесь JSONObject ["time"], а не строка - ошибкая сталкиваюсь, когда помещаю это в JSONArray