You cannot use ARRAYOFCONST()
or OPENARRAY()
to create a 0-element openarray. Those macros require a minimum of 1 input value.
I am not familiar with SuperObject, but if O[]
creates a new JSON array from existing values and A[]
simply fills the array, you could try using the SLICE()
macro to create and fill an openarray from v
directly if v
is a std::vector<TVarRec>
:
if (!v.empty())
json->O["data.names"] = SA( SLICE(&v[0], v.size()) );
If you really need a 0-element openarray if v
is empty, try this:
if (v.empty())
json->O["data.names"] = SA( NULL, -1 );
else
json->O["data.names"] = SA( SLICE(&v[0], v.size()) );
If v
does not contain TVarRec
values then you can create a separate std::vector<TVarRec>
first and then SLICE()
that into SuperObject (just be careful because TVarRec
does not perform reference counting on reference-counted data types, such as strings - by design - so make sure temporaries are not created when you assign the TVarRec
values or else they will be leaked!):
if (v.empty())
json->O["data.names"] = SA( NULL, -1 );
else
{
std:vector<TVarRec> tmp(v.size());
for (size_t idx = 0; idx < v.size(); ++idx)
tmp[idx] = v[idx];
json->O["data.names"] = SA( SLICE(&tmp[0], tmp.size()) );
}