-1

I want to make a Arraylist with JSON Objects .

There is a loop which gives me JSON Objects. I want to put them into a ArrayList.

Here is the Code which gives me JSON Objects. Please let me know how to put all the values ito a ArrayList

for (int i=0; i<10; i++) {
    String datapointsBodyString = "{items:[{id:" + unionUptimeMetadata.getLatencyTimeseriesIds().get(i) + ", start: " + oldestTimeString + ",end: " + now + ", granularity: 1m}]}";
    JSONObject datapointsBodyObject = new JSONObject((datapointsBodyString));

    HttpResponse uptimeResponse = httpService.POST("url", datapointsBodyObject.toString(), unionUptimeTimeseriesHeaders);
    HttpEntity uptimeResponseEntity = uptimeResponse.getEntity();
    String uptimeResponseString = EntityUtils.toString(uptimeResponseEntity);
    JSONObject uptimeResponsObject = new JSONObject(uptimeResponseString);
}

Thanks in advance.

2

1 Answer 1

0

It's generally worth doing a search for common programming tasks. You could just google search "java add to list" which should result in something like:

List<JSONObject> myList = new ArrayList<>();

myList.add(uptimeResponsObject);

that should be enough for you to get it working.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.