sof question
sof question

Reputation: 93

How to make JsonArray clear in android?

I am building and android application and using pull down referees. I wanna to clear the old jsonArray data and reload the new data that coming from server.

I have tried many thinking like - JsonArray test = new JsonArray(), JsonArray test("[]");

but nothing is working can some one help me in solving this.

Upvotes: 2

Views: 1320

Answers (2)

Cherno Omar Senghore
Cherno Omar Senghore

Reputation: 27

You need to run a while loop across the length of the test and at each time delete the first index. the loop will reach a stage when the length of the test is zero to show the test is not empty and and cleared.

while (test.length() > 0) {
        test.remove(0)
}

Upvotes: 1

Piotr Wittchen
Piotr Wittchen

Reputation: 3922

Try this for clearing JSONArray:

jsonArray = new JSONArray(new ArrayList<String>());

Upvotes: 2

Related Questions