Development with openABK openABK development resources

CJsonStreamObject

class CJsonStreamObject : public CJsonStreamBase

With the instantiation of CJsonStreamObject you can add an object to an object (or formatter) or to an array. When falling out of scope, the object is closed and the necessary closing braces are appended to the formatted result.

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

The variants with CJsonStreamObject as parent are used to place an object 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 object into an array.

Appending Value Members

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

WriteValue appends data members to the objects. The int, bool, double, char *, std::string and time_t variants simply append members in the style "name":value. String values are escaped according the JSON specification. The strName argument is the name of the value and will be escaped too.

Appending objects

void WriteValue (const char *strName, CJsonFormatter &objPut); // writes object
void WriteValue (CJsonFormatter &objPut); // writes members of an object into the object

These overloaded members add already formatted objects to the object by copying the content. The variant with strName copies the object as object and strName gives the name for the object. The variant without strName copies each member separately to the object.

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

Appending Arrays

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

 

openABK