From c484829272cd13a738e35412498e12f2c9a194ac Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:48:59 +0200 Subject: Adding upstream version 0.19.2. Signed-off-by: Daniel Baumann --- doc_example/json_parser_1.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 doc_example/json_parser_1.cpp (limited to 'doc_example/json_parser_1.cpp') 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 +#include +#include + +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 parser(test_code, hdl); + + // Parse the string. + parser.parse(); + + return EXIT_SUCCESS; +} -- cgit v1.2.3