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

Function main

lib_acl_cpp/samples/json/json3/json.cpp:6–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4 */
5
6int main()
7{
8 const char* type = "set";
9 const char* tablename = "\txmailuser";
10 const char* name = " chenzhen";
11
12 printf(">>>>{%s}\r\n", tablename);
13 acl::json json;
14 acl::json_node& first = json.get_root().add_child(false, true);
15 first.add_text("type", type);
16 first.add_text("tablename", tablename);
17 first.add_text("name", name);
18
19 // ����json�ַ���
20 printf("json to string:%s\r\n", json.to_string().c_str());
21 printf("first json node to string: %s\r\n", first.to_string().c_str());
22
23 acl::string buf;
24 json.build_json(buf);
25 // �������ɵ��ַ�����ȡ��ֵ
26 acl::json json2(first);
27 acl::json_node* root2 = &json2.get_root();
28 acl::json_node* child = root2->first_child();
29
30 printf(">>>json2: %s|%s\r\n", json2.to_string().c_str(), buf.c_str());
31
32 const char* tag, *txt;
33 while (child != NULL)
34 {
35 if ((tag = child->tag_name()) != NULL && *tag != 0
36 && (txt = child->get_text()) != NULL && *txt != 0)
37 {
38 printf("tag: %s, txt: %s\n", tag, txt);
39 }
40 else
41 printf("no tag name or no txt in json node");
42
43 child = root2->next_child();
44 }
45 printf("\r\n");
46
47 /////////////////////////////////////
48
49 const char* sss = "{\"DataKey\": \"BindRule\", \"DataValue\": {\"waittime\": \"7\"}, \"null_key\": null}";
50
51 acl::json json3(sss);
52 const char* tags = "DataValue";
53
54 printf("----------------------------------------------------\r\n");
55 printf(">>%s\r\n", sss);
56 acl::json_node* iter = json3.first_node();
57 while (iter)
58 {
59 tag = iter->tag_name();
60 txt = iter->get_text();
61 printf("tag: %s, txt: %s\r\n", tag ? tag : "null", txt ? txt : "null");
62 if (txt)
63 iter->set_text("hello");

Callers

nothing calls this directly

Calls 11

build_jsonMethod · 0.80
get_textMethod · 0.80
set_textMethod · 0.80
c_strMethod · 0.45
to_stringMethod · 0.45
first_childMethod · 0.45
tag_nameMethod · 0.45
next_childMethod · 0.45
first_nodeMethod · 0.45
next_nodeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…