class Poco::JSON::PrintHandler
Overview
PrintHandler formats and prints the JSON object to either user-provided std::ostream or standard output. More…
#include <PrintHandler.h> class PrintHandler: public Poco::JSON::Handler { public: // typedefs typedef SharedPtr<PrintHandler> Ptr; // fields static const unsigned JSON_PRINT_FLAT; // construction PrintHandler(unsigned indent = 0); PrintHandler( std::ostream& out, unsigned indent = 0 ); // methods virtual void reset(); virtual void startObject(); virtual void endObject(); virtual void startArray(); virtual void endArray(); virtual void key(const std::string& k); virtual void null(); virtual void value(int v); virtual void value(unsigned v); virtual void value(const std::string& value); virtual void value(double d); virtual void value(bool b); void comma(); void setIndent(unsigned indent); };
Inherited Members
public: // typedefs typedef SharedPtr<Handler> Ptr; // methods virtual void reset() = 0; virtual void startObject() = 0; virtual void endObject() = 0; virtual void startArray() = 0; virtual void endArray() = 0; virtual void key(const std::string& k) = 0; virtual void null() = 0; virtual void value(int v) = 0; virtual void value(unsigned v) = 0; virtual void value(const std::string& value) = 0; virtual void value(double d) = 0; virtual void value(bool b) = 0; virtual Poco::Dynamic::Var asVar() const; virtual Poco::DynamicStruct asStruct() const;
Detailed Documentation
PrintHandler formats and prints the JSON object to either user-provided std::ostream or standard output.
If indent is zero, the output is a condensed JSON string, otherwise, the proper indentation is applied to elements.
Construction
PrintHandler(unsigned indent = 0)
Creates the PrintHandler.
PrintHandler( std::ostream& out, unsigned indent = 0 )
Creates the PrintHandler.
Methods
virtual void reset()
Resets the handler state.
virtual void startObject()
The parser has read a ‘{‘; a new object is started.
If indent is greater than zero, a newline will be appended.
virtual void endObject()
The parser has read a ‘}’; the object is closed.
virtual void startArray()
The parser has read a [; a new array will be started.
If indent is greater than zero, a newline will be appended.
virtual void endArray()
The parser has read a ]; the array is closed.
virtual void key(const std::string& k)
A key of an object is read; it will be written to the output, followed by a ‘:’.
If indent is greater than zero, the colon is padded by a space before and after.
virtual void null()
A null value is read; “null” will be written to the output.
virtual void value(int v)
An integer value is read.
virtual void value(unsigned v)
An unsigned value is read.
This will only be triggered if the value cannot fit into a signed int.
virtual void value(const std::string& value)
A string value is read; it will be formatted and written to the output.
virtual void value(double d)
A double value is read; it will be written to the output.
virtual void value(bool b)
A boolean value is read; it will be written to the output.
void comma()
A comma is read; it will be written to the output as “true” or “false”.
void setIndent(unsigned indent)
Sets indentation.