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

Function main

lib_acl_cpp/samples/json/json14/json.cpp:8–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6}
7
8int main(int argc, char* argv[]) {
9 acl::string file;
10 int ch;
11
12 while ((ch = getopt(argc, argv, "hf:")) > 0) {
13 switch (ch) {
14 case 'h':
15 usage(argv[0]);
16 return 0;
17 case 'f':
18 file = optarg;
19 break;
20 default:
21 break;
22 }
23 }
24
25 if (file.empty()) {
26 usage(argv[0]);
27 return 1;
28 }
29
30 acl::string buf;
31 if (!acl::ifstream::load(file, &buf)) {
32 printf("load %s error %s\r\n", file.c_str(), acl::last_serror());
33 return 1;
34 }
35
36 acl::json json(buf);
37 if (!json.finish()) {
38 printf("invalid json: %s\r\n", buf.c_str());
39 return 1;
40 }
41
42 printf("parse json ok: %s\r\n", json.to_string().c_str());
43
44 json.reset();
45 json.get_root().add_array(true)
46 .add_array_text("name1")
47 .add_array_text("name2")
48 .add_array_text("name3");
49 printf("build json: %s\r\n", json.to_string().c_str());
50
51 json.reset();
52 json.get_root().add_text("name1", "value1")
53 .add_text("name2", "value2")
54 .add_text("name3", "value3")
55 .add_number("name4", 100);
56 printf("build json: %s\r\n", json.to_string().c_str());
57
58 json.reset();
59 json.get_root().add_text("name1", "value1");
60 printf("build json: %s\r\n", json.to_string().c_str());
61
62 json.reset();
63 json.get_root().add_child(false, true)
64 .add_text("name1", "value1")
65 .add_text("name2", "value2")

Callers

nothing calls this directly

Calls 12

add_arrayMethod · 0.80
set_tagMethod · 0.80
set_textMethod · 0.80
usageFunction · 0.70
getoptFunction · 0.50
last_serrorFunction · 0.50
emptyMethod · 0.45
c_strMethod · 0.45
finishMethod · 0.45
to_stringMethod · 0.45
resetMethod · 0.45
create_nodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…