Development with openABK openABK development resources


class CJsonStreamArray : public CJsonStreamBase

With the instantiation of CJsonStreamArray you can add an array to an object or to an array. When falling out of scope, the array is closed and the necessary closing tags are appended to the formatted result.

  (CJsonStreamObject *pParent, const char *strName);
  (CJsonStreamObject *pParent, const std::string &strName);
  (CJsonStreamArray *pParent);

The variants with CJsonStreamObject as parent are used to place an array into an object. Note that the parent can be a CJsonFormatter, which is an object in turn. The variant with CJsonStreamArray as parent is used to place an array into an array.

Appending Value Members

void WriteValue (int nValue); // writes integer value
void WriteValue (bool bValue); // writes bool value
void WriteValue (double dValue); // writes double precision value
void WriteValue (const char *strValue); // writes string value
void WriteValue (const std::string &strValue); // writes string value
void WriteValue (time_t tmDateLocal); // writes date and time

WriteValue appends and formats data members to the array. In contrast to the Write() members of the CJsonStreamObject, no name is needed since array members do not have names.

Appending objects

void WriteValue (CJsonFormatter &objPut); // writes already formatted object

This overloaded member adds an already formatted object to the array by copying the content.

A more elegant way to add objects to the array is adding them inline. This can be accomplished by creating an instance of CJsonStreamObject object by referring the parent array.

Appending Arrays

Arrays can be added inline by creating another instance of CJsonStreamArray object with a pointer to the parent array. Then the array members can be appended with the help of the CJsonStreamArray object.

Closing the Array

When you are finished with adding members to the array, you have to ensure that the array is closed.

void Close (void); // closes the array and writes closing tags (i.e. "]")

The array gets closed automatically when it is deleted or falls out-of-scope.