How to clear JSONArray

How to clear data from JSONArray

there is nothing like it:

jsonArray.clear(); 

:

 jsonArray.remove(index); 

which was suggested here:

How to remove a specific item from a JSONArray?

thanks

+4
source share
6 answers
 jsonArray = new JSONArray(new ArrayList<String>()); 
+13
source

this is not a perfect answer, but you can do it,

 jsonArray=new jsonArray("[{}]"); 
+2
source

Newly made local variables

 JSONArray jsonArray = new JSONArray(); jsonArray.put(productlist); 

Every time jsonserver data is added using local block, if u declear is global block then jsonarray needs to be cleared

+1
source

In the library I have, there is no way to call clear() private ArrayList inside a JSONObject . However, it has public Object remove(int index) . I just use new JSONObject() : (

0
source

I try everything, but the only thing that worked for me was

 JSONarray=null; 
-1
source

this is one answer try:

 jsonArray=[] 
-2
source

All Articles