| 6 | } |
| 7 | |
| 8 | int 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") |
nothing calls this directly
no test coverage detected
searching dependent graphs…