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

Function parse_json

lib_acl/samples/json/json2/main.cpp:37–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35"}\r\n";
36
37static void parse_json(const char *data)
38{
39 ACL_JSON *json = acl_json_alloc();
40 ACL_JSON *json_new;
41 ACL_VSTRING *buf1 = acl_vstring_alloc(128);
42 ACL_VSTRING *buf2 = acl_vstring_alloc(128);
43 ACL_ARRAY *nodes;
44 ACL_JSON_NODE *one_node;
45 const char *tags;
46
47 printf("buf src: %s\r\n", data);
48
49 printf("------------------------------------------------\r\n");
50
51 json->flag |= ACL_JSON_FLAG_PART_WORD;
52 acl_json_update(json, data);
53 acl_json_build(json, buf1);
54 printf("buf src: %s\r\n", STR(buf1));
55
56 printf("------------------------------------------------\r\n");
57
58 tags = "popup/menuitem";
59 if (1)
60 tags = "popup";
61 else if (1)
62 tags = "help";
63 else
64 tags = "popup/menuitem/*/onclick";
65
66 nodes = acl_json_getElementsByTags(json, tags);
67 if (nodes)
68 one_node = (ACL_JSON_NODE*) acl_array_index(nodes, 0);
69 else
70 one_node = NULL;
71
72 printf(">>>tags: %s\r\n", tags);
73 if (one_node == NULL)
74 json_new = acl_json_create(json->root);
75 else
76 json_new = acl_json_create(one_node);
77
78 json_new->flag |= ACL_JSON_FLAG_PART_WORD;
79
80 acl_json_build(json_new, buf2);
81 printf("buf dst: %s\r\n", STR(buf2));
82
83 printf("------------------------------------------------\r\n");
84
85 if (nodes == NULL && strcmp(STR(buf1), STR(buf2)) != 0)
86 printf("ERROR, not equal!\r\n");
87 else
88 printf("OK\r\n");
89
90 if (nodes)
91 acl_json_free_array(nodes);
92
93 acl_json_free(json);
94 acl_json_free(json_new);

Callers 1

mainFunction · 0.70

Calls 10

acl_json_allocFunction · 0.85
acl_vstring_allocFunction · 0.85
acl_json_updateFunction · 0.85
acl_json_buildFunction · 0.85
acl_array_indexFunction · 0.85
acl_json_createFunction · 0.85
acl_json_free_arrayFunction · 0.85
acl_json_freeFunction · 0.85
acl_vstring_freeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…