1 #include "rapidjson/reader.h"
2 #include <iostream>
3
4 using namespace rapidjson;
5 using namespace std;
6
7 struct MyHandler {
NullMyHandler8 bool Null() { cout << "Null()" << endl; return true; }
BoolMyHandler9 bool Bool(bool b) { cout << "Bool(" << boolalpha << b << ")" << endl; return true; }
IntMyHandler10 bool Int(int i) { cout << "Int(" << i << ")" << endl; return true; }
UintMyHandler11 bool Uint(unsigned u) { cout << "Uint(" << u << ")" << endl; return true; }
Int64MyHandler12 bool Int64(int64_t i) { cout << "Int64(" << i << ")" << endl; return true; }
Uint64MyHandler13 bool Uint64(uint64_t u) { cout << "Uint64(" << u << ")" << endl; return true; }
DoubleMyHandler14 bool Double(double d) { cout << "Double(" << d << ")" << endl; return true; }
StringMyHandler15 bool String(const char* str, SizeType length, bool copy) {
16 cout << "String(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl;
17 return true;
18 }
StartObjectMyHandler19 bool StartObject() { cout << "StartObject()" << endl; return true; }
KeyMyHandler20 bool Key(const char* str, SizeType length, bool copy) {
21 cout << "Key(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl;
22 return true;
23 }
EndObjectMyHandler24 bool EndObject(SizeType memberCount) { cout << "EndObject(" << memberCount << ")" << endl; return true; }
StartArrayMyHandler25 bool StartArray() { cout << "StartArray()" << endl; return true; }
EndArrayMyHandler26 bool EndArray(SizeType elementCount) { cout << "EndArray(" << elementCount << ")" << endl; return true; }
27 };
28
main()29 int main() {
30 const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } ";
31
32 MyHandler handler;
33 Reader reader;
34 StringStream ss(json);
35 reader.Parse(ss, handler);
36
37 return 0;
38 }
39