Library: JSON
Package: JSON
Header: Poco/JSON/Parser.h
Description
A RFC 4627 compatible class for parsing JSON strings or streams.
See http://www.ietf.org/rfc/rfc4627.txt for specification.
Usage example:
std::string json = "{ \"name\" : \"Franky\", \"children\" : [ \"Jonas\", \"Ellen\" ] }"; Parser parser; Var result = parser.parse(json); // ... use result parser.reset(); std::ostringstream ostr; PrintHandler::Ptr pHandler = new PrintHandler(ostr); parser.setHandler(pHandler); parser.parse(json); // ostr.str() == json
Member Summary
Member Functions: asVar, getAllowComments, getAllowNullByte, getDepth, getHandler, parse, reset, result, setAllowComments, setAllowNullByte, setDepth, setHandler
Types
CharIntType
typedef CharTraits::int_type CharIntType;
CharTraits
typedef std::char_traits < char > CharTraits;
Enumerations
Actions
CB = - 10
CE = - 11
FA = - 12
TR = - 13
NU = - 14
DE = - 15
DF = - 16
SB = - 17
MX = - 18
ZX = - 19
IX = - 20
EX = - 21
UC = - 22
Classes
JSONType
JSON_T_NONE = 0
Modes
Modes that can be pushed on the _pStack.
MODE_ARRAY = 1
MODE_DONE = 2
MODE_KEY = 3
MODE_OBJECT = 4
States
State codes
Constructors
Parser
Parser(
const Handler::Ptr & pHandler = new ParseHandler,
std::size_t bufSize = JSON_PARSE_BUFFER_SIZE
);
Destructor
~Parser
virtual ~Parser();
Member Functions
asVar
Dynamic::Var asVar() const;
Returns the result of parsing;
getAllowComments
bool getAllowComments() const;
Returns true if comments are allowed, false otherwise. By default, comments are not allowed.
getAllowNullByte
bool getAllowNullByte() const;
Returns true if null byte is allowed, false otherwise. By default, null bytes are allowed.
getDepth
std::size_t getDepth() const;
Returns the allowed JSON depth.
getHandler
const Handler::Ptr & getHandler();
Returns the handler.
parse
Dynamic::Var parse(
const std::string & json
);
Parses a string.
parse
Dynamic::Var parse(
std::istream & in
);
Parses a JSON from the input stream.
reset
void reset();
Resets the parser.
result
Dynamic::Var result() const;
Returns the result of parsing as Dynamic::Var;
setAllowComments
void setAllowComments(
bool comments
);
Allow comments. By default, comments are not allowed.
setAllowNullByte
void setAllowNullByte(
bool nullByte
);
Allow null byte in strings. By default, null byte is allowed.
setDepth
void setDepth(
std::size_t depth
);
Sets the allowed JSON depth.
setHandler
void setHandler(
const Handler::Ptr & pHandler
);
Set the handler.
Variables
JSON_PARSER_STACK_SIZE
static const std::size_t JSON_PARSER_STACK_SIZE = 128;
JSON_PARSE_BUFFER_SIZE
static const std::size_t JSON_PARSE_BUFFER_SIZE = 4096;
JSON_UNLIMITED_DEPTH
static const int JSON_UNLIMITED_DEPTH = - 1;