I am working on a project where I have to clear all the data from a JSON array. There seems to be no method like jsonArray.clear(). Also tried jsonArray = new JSONArray(). That too didn't worked. Suggestions please
You can remove an element from the JSONArray object using the remove() method. This method accepts an integer and removes the element in that particular index.
To delete a JSON object from a list: Parse the JSON object into a Python list of dictionaries. Use the enumerate() function to iterate over the iterate over the list. Check if each dictionary is the one you want to remove and use the pop() method to remove the matching dict.
JsonObject::remove() removes a key-value pair from the object pointed by the JsonObject . If the JsonObject is null, this function does nothing.
JSON has a special value called null which can be set on any type of data including arrays, objects, number and boolean types.
Just create a new JSONArray.
JSONArray otherJsonArray = new JSONArray();
Or iterate through the array and remove(int index)
the indexes.
http://www.json.org/javadoc/org/json/JSONArray.html#remove(int)
Just put jsonArray = new JSONArray()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With