MCPcopy Create free account
hub / github.com/acl-dev/acl / main

Function main

lib_acl_cpp/samples/json/json13/json.cpp:6–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4 */
5
6int main(void)
7{
8 const char* s = "{ 'cmd': 'GET',\r\n"
9 "'data': { 'count': 2, iptables: [\r\n"
10 " {'test1': '192.168.1.1'},\r\n"
11 " {'test2': '192.168.1.2'},\r\n"
12 " {'test3': '192.168.1.3'},\r\n"
13 " {'test4': '192.168.1.4'},\r\n"
14 " {'test5': '192.168.1.5'},\r\n"
15 " {'test6': '192.168.1.6'},\r\n"
16 " {'test7': 192 },\r\n"
17 " {'test8': true}\r\n"
18 "]}}";
19
20
21 acl::json json(s);
22 const char* tags = "data/iptables";
23
24 acl::json_node* node = json.getFirstElementByTags(tags);
25 if (node == NULL)
26 {
27 printf("no tags: %s\r\n", tags);
28 return 0;
29 }
30
31 printf("tag: %s, type: %s\r\n", node->tag_name(), node->get_type());
32
33 acl::json_node* array = node->get_obj();
34 if (array == NULL)
35 {
36 printf("get_obj null\r\n");
37 return 0;
38 }
39 if (array->is_array() == false)
40 {
41 printf("not array: %s\r\n", array->to_string().c_str());
42 return 0;
43 }
44 else
45 printf("Array: %s\r\n", array->to_string().c_str());
46
47 printf("-------------------------------------------------------\r\n");
48
49 acl::json_node* child = array->first_child();
50 while (child)
51 {
52 printf("type: %s->%s\r\n", child->get_type(),
53 child->to_string().c_str());
54
55 acl::json_node* o = (*child)["test1"];
56 if (o)
57 printf(">>> found, test1: %p\r\n", o);
58
59 acl::json_node* iter = child->first_child();
60 while (iter)
61 {
62 printf("type: %s, string: %s, tag: %s, txt: %s\r\n",
63 iter->get_type(), iter->to_string().c_str(),

Callers

nothing calls this directly

Calls 10

get_objMethod · 0.80
is_arrayMethod · 0.80
get_textMethod · 0.80
getFirstElementByTagsMethod · 0.45
tag_nameMethod · 0.45
get_typeMethod · 0.45
c_strMethod · 0.45
to_stringMethod · 0.45
first_childMethod · 0.45
next_childMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…