File: json_parser_1.cpp

package info (click to toggle)
liborcus 0.20.1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 16,644 kB
  • sloc: xml: 78,349; cpp: 74,365; sh: 4,626; makefile: 2,787; python: 2,614
file content (41 lines) | stat: -rw-r--r-- 842 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
}