17 RAPIDJSON_DIAG_OFF(effc++)
22 RAPIDJSON_DIAG_OFF(
switch-
enum)
31 case kExpectObjectStart:
32 state_ = kExpectNameOrObjectEnd;
41 case kExpectNameOrObjectEnd:
42 name_ =
string(str, length);
43 state_ = kExpectValue;
46 messages_.insert(MessageMap::value_type(name_,
string(str, length)));
47 state_ = kExpectNameOrObjectEnd;
75 static void ParseMessages(
const char*
json,
MessageMap& messages) {
79 if (reader.
Parse(ss, handler))
85 cout <<
" at offset " << o <<
" near '" <<
string(
json).substr(o, 10) <<
"...'" << endl;
92 const char* json1 =
"{ \"greeting\" : \"Hello!\", \"farewell\" : \"bye-bye!\" }";
93 cout << json1 << endl;
94 ParseMessages(json1, messages);
96 for (MessageMap::const_iterator itr = messages.begin(); itr != messages.end(); ++itr)
97 cout << itr->first <<
": " << itr->second << endl;
99 cout << endl <<
"Parse a JSON with invalid schema." << endl;
100 const char* json2 =
"{ \"greeting\" : \"Hello!\", \"farewell\" : \"bye-bye!\", \"foo\" : {} }";
101 cout << json2 << endl;
102 ParseMessages(json2, messages);
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
ParseErrorCode
Error code of parsing.
map< string, string > MessageMap
ParseResult Parse(InputStream &is, Handler &handler)
Parse JSON text.
Default implementation of Handler.
RAPIDJSON_NAMESPACE_BEGIN const RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
ParseErrorCode GetParseErrorCode() const
Get the ParseErrorCode of last parsing.
bool String(const char *str, SizeType length, bool)
size_t GetErrorOffset() const
Get the position of last parsing error in input, 0 otherwise.