summaryrefslogtreecommitdiffstats
path: root/doc_example/json_parser_1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'doc_example/json_parser_1.cpp')
-rw-r--r--doc_example/json_parser_1.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/doc_example/json_parser_1.cpp b/doc_example/json_parser_1.cpp
new file mode 100644
index 0000000..322316a
--- /dev/null
+++ b/doc_example/json_parser_1.cpp
@@ -0,0 +1,41 @@
+
+#include <orcus/json_parser.hpp>
+#include <cstring>
+#include <iostream>
+
+using namespace std;
+
+class json_parser_handler : public orcus::json_handler
+{
+public:
+ void object_key(std::string_view key, bool /*transient*/)
+ {
+ cout << "object key: " << key << endl;
+ }
+
+ void string(std::string_view val, bool /*transient*/)
+ {
+ cout << "string: " << val << endl;
+ }
+
+ void number(double val)
+ {
+ cout << "number: " << val << endl;
+ }
+};
+
+int main()
+{
+ const char* test_code = "{\"key1\": [1,2,3,4,5], \"key2\": 12.3}";
+
+ cout << "JSON string: " << test_code << endl;
+
+ // Instantiate the parser with an own handler.
+ json_parser_handler hdl;
+ orcus::json_parser<json_parser_handler> parser(test_code, hdl);
+
+ // Parse the string.
+ parser.parse();
+
+ return EXIT_SUCCESS;
+}