blob: 322316a13bf0a73a7e6f6f7d0a3ee88db9db716e (
plain)
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;
}
|