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

Function parse_json

lib_acl/samples/json/json3/main.cpp:29–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27#endif
28
29static void parse_json(const char *data)
30{
31 ACL_JSON *json = acl_json_alloc();
32 ACL_VSTRING *buf1 = acl_vstring_alloc(128);
33 ACL_VSTRING *buf2 = acl_vstring_alloc(128);
34 ACL_ARRAY *nodes;
35 const char *tag = "header";
36
37 printf("buf src: %s\r\n", data);
38
39 printf("------------------------------------------------\r\n");
40
41 acl_json_update(json, data);
42 acl_json_build(json, buf1);
43 printf("result src: %s\r\n", STR(buf1));
44
45 printf("------------------------------------------------\r\n");
46
47 nodes = acl_json_getElementsByTagName(json, tag);
48 if (nodes == NULL)
49 {
50 printf("not found tag: %s\r\n", tag);
51 acl_vstring_free(buf1);
52 acl_vstring_free(buf2);
53 acl_json_free(json);
54 return;
55 }
56
57 printf(">>>tag: %s, len: %d\r\n", tag, acl_array_size(nodes));
58
59 ACL_ITER iter;
60
61#define STR acl_vstring_str
62#define LEN ACL_VSTRING_LEN
63
64 acl_foreach(iter, nodes)
65 {
66 ACL_JSON_NODE *node = (ACL_JSON_NODE*) iter.data;
67 ACL_JSON_NODE *tag_node = node->tag_node;
68 if (tag_node == NULL)
69 continue;
70
71 printf(">>>tag: %s\r\n", STR(node->ltag));
72
73 ACL_ITER iter2;
74 acl_foreach(iter2, tag_node)
75 {
76 ACL_JSON_NODE *node1 = (ACL_JSON_NODE*) iter2.data;
77 if (node1->ltag == NULL || LEN(node1->ltag) == 0)
78 continue;
79 printf(">>>child tag: %s, txt: %s\r\n", STR(node1->ltag),
80 node1->text ? STR(node1->text) : "null");
81 }
82 }
83
84 if (nodes)
85 acl_json_free_array(nodes);
86

Callers 1

mainFunction · 0.70

Calls 9

acl_json_allocFunction · 0.85
acl_vstring_allocFunction · 0.85
acl_json_updateFunction · 0.85
acl_json_buildFunction · 0.85
acl_vstring_freeFunction · 0.85
acl_json_freeFunction · 0.85
acl_array_sizeFunction · 0.85
acl_json_free_arrayFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…