Defining JSONArray with name but without array

I am trying to define a JSONArray within a JSON object but I will be adding objects in array later.
So when declaring it , I cannot use setJSONArray function.
How can I retrieve it by getJSONArray function if I have not
named it.
Is there a way to declare JSONArray with name and append in it later?

Both methods JSONObject::setJSONArray() & JSONObject::getJSONArray() require a named key parameter as their 1st passed argument.

B/c every time we add a new JSONArray object to an existing JSONObject via its method setJSONArray() we must pass a String as the 1st argument, that JSONArray will surely have a named property key within that JSONObject.

Once you access that JSONArray later via method JSONObject::getJSONArray() you’ll be able to add any kind of valid JSON values to it via its method JSONArray::append(), including even other JSONObject objects:

1 Like