blob: d1aa07d3033d60e7d8c35f1e5c180b417c1f5802 (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#include "include/types.h"
#include <string.h>
#include <map>
#include "rgw_json.h"
using namespace std;
#define dout_subsys ceph_subsys_rgw
void dump_array(JSONObj *obj)
{
JSONObjIter iter = obj->find_first();
for (; !iter.end(); ++iter) {
JSONObj *o = *iter;
cout << "data=" << o->get_data() << endl;
}
}
int main(int argc, char **argv) {
RGWJSONParser parser;
char buf[1024];
for (;;) {
int done;
int len;
len = fread(buf, 1, sizeof(buf), stdin);
if (ferror(stdin)) {
cerr << "read error" << std::endl;
exit(-1);
}
done = feof(stdin);
bool ret = parser.parse(buf, len);
if (!ret)
cerr << "parse error" << std::endl;
if (done)
break;
}
JSONObjIter iter = parser.find_first();
for (; !iter.end(); ++iter) {
JSONObj *obj = *iter;
cout << "is_object=" << obj->is_object() << endl;
cout << "is_array=" << obj->is_array() << endl;
cout << "name=" << obj->get_name() << endl;
cout << "data=" << obj->get_data() << endl;
}
iter = parser.find_first("conditions");
if (!iter.end()) {
JSONObj *obj = *iter;
JSONObjIter iter2 = obj->find_first();
for (; !iter2.end(); ++iter2) {
JSONObj *child = *iter2;
cout << "is_object=" << child->is_object() << endl;
cout << "is_array=" << child->is_array() << endl;
if (child->is_array()) {
dump_array(child);
}
cout << "name=" << child->get_name() << endl;
cout << "data=" << child->get_data() << endl;
}
}
exit(0);
}
|