JsonParser class parses a json string into a Variant structure.
#include <json.h>
Inheritance diagram for jvar::JsonParser:
Collaboration diagram for jvar::JsonParser:Public Types | |
| enum | { FLAG_FLEXQUOTES = 0x1, FLAG_OBJECTONLY = 0x2, FLAG_ARRAYONLY = 0x4 } |
Public Member Functions | |
| JsonParser (Variant &outvar, const char *jsontxt, uint flags=0) | |
| bool | eof () |
| bool | failed () |
| const std::string & | errMsg () |
| const char * | c_str () |
| const std::string & | token () |
| bool | tokenEquals (const char *val) |
| void | advance () |
| void | advance (const char *match) |
| void | setError (const char *msg) |
| void | stripQuotes (bool allowsingle) |
| void | captureDelim (const char *delim) |
Protected Member Functions | |
| void | parseObject (Variant &var) |
| void | parseMembers (Variant &var) |
| void | parseArray (Variant &var) |
| void | parseElements (Variant &var) |
| void | parseValue (Variant &var) |
| void | parseNum (Variant &var) |
| void | parseString (Variant &var) |
| bool | isString (const std::string &s, bool requirequotes) |
| bool | isArray (const std::string &s) |
| bool | isObject (const std::string &s) |
| bool | isNum (const std::string &s) |
| bool | charWord (char c) |
| bool | charPunc (char c) |
| bool | charBrac (char c) |
Protected Attributes | |
| uint | mFlags |
| anonymous enum |
| jvar::JsonParser::JsonParser | ( | Variant & | outvar, |
| const char * | jsontxt, | ||
| uint | flags = 0 |
||
| ) |
Constructor
| outvar | Variant which will contain the parsed data structure |
| jsontxt | Json text to parse |
| flags | Flags |
References jvar::Parser::advance(), jvar::Parser::c_str(), jvar::Parser::eof(), jvar::Parser::errMsg(), jvar::Parser::failed(), FLAG_ARRAYONLY, FLAG_OBJECTONLY, jvar::Parser::setError(), jvar::Parser::token(), and jvar::Parser::tokenEquals().
| void jvar::Parser::advance | ( | ) | [inline, inherited] |
Advances to the next token by parsing it
Referenced by jvar::Parser::advance(), JsonParser(), and jvar::Variant::path().
| void jvar::Parser::advance | ( | const char * | match | ) | [inherited] |
Advances if a matching token is found
| match | String to match |
References jvar::Parser::advance(), jvar::Parser::c_str(), jvar::Parser::setError(), jvar::Parser::token(), and jvar::Parser::tokenEquals().
| const char* jvar::Parser::c_str | ( | ) | [inline, inherited] |
Returns the current token
References jvar::Parser::token().
Referenced by jvar::Parser::advance(), and JsonParser().
| bool jvar::Parser::eof | ( | ) | [inline, inherited] |
Is the entire text parsed
Referenced by JsonParser(), and jvar::Variant::path().
| const std::string& jvar::Parser::errMsg | ( | ) | [inline, inherited] |
Returns the error message
Referenced by JsonParser().
| bool jvar::Parser::failed | ( | ) | [inline, inherited] |
Was there a failure
Referenced by JsonParser(), and jvar::Variant::parseJson().
| void jvar::Parser::setError | ( | const char * | msg | ) | [inherited] |
Sets an error message and signal failure
| msg | Error text |
Referenced by jvar::Parser::advance(), JsonParser(), and jvar::Parser::Parser().
| void jvar::Parser::stripQuotes | ( | bool | allowsingle | ) | [inherited] |
Strip quotes from the current token string if found
| allowsingle | If true, also allows stripping single quotes |
| const std::string& jvar::Parser::token | ( | ) | [inline, inherited] |
Returns the current token
Referenced by jvar::Parser::advance(), jvar::Parser::c_str(), JsonParser(), jvar::Variant::path(), and jvar::Parser::tokenEquals().
| bool jvar::Parser::tokenEquals | ( | const char * | val | ) | [inline, inherited] |
Compares the current token with a string
| val | String to compare |
References jvar::Parser::token().
Referenced by jvar::Parser::advance(), JsonParser(), and jvar::Variant::path().