| 1 | #include "stdafx.h" |
| 2 | |
| 3 | int main() |
| 4 | { |
| 5 | const char* sss = |
| 6 | "[" |
| 7 | "{\"DataKey\":\"BindRule\",\"DataValue\":{\"waittime\":\"7\"},\"null_key\":null}," |
| 8 | "{\"DataKey\":\"BindRule\",\"DataValue\":{\"waittime\":\"7\"},\"null_key\":null}" |
| 9 | "]"; |
| 10 | |
| 11 | acl::json json3(sss); |
| 12 | const char* tags = "DataValue"; |
| 13 | |
| 14 | printf("----------------------------------------------------\r\n"); |
| 15 | printf(">>%s\r\n", sss); |
| 16 | const acl::string& s = json3.to_string(); |
| 17 | printf(">>%s\r\n", s.c_str()); |
| 18 | |
| 19 | if (json3.to_string() == sss) |
| 20 | printf("parse OK, enter any key to continue\r\n"); |
| 21 | else |
| 22 | { |
| 23 | printf("parse ERROR\r\n"); |
| 24 | return 1; |
| 25 | } |
| 26 | |
| 27 | getchar(); |
| 28 | |
| 29 | printf("----------------------------------------------------\r\n"); |
| 30 | |
| 31 | acl::json_node* iter = json3.first_node(); |
| 32 | while (iter) |
| 33 | { |
| 34 | const char* tag = iter->tag_name(); |
| 35 | const char* txt = iter->get_text(); |
| 36 | printf("tag: %s, txt: %s\r\n", tag ? tag : "null", txt ? txt : "null"); |
| 37 | if (txt) |
| 38 | iter->set_text("hello"); |
| 39 | printf("tag: %s, txt: %s\r\n", tag ? tag : "null", txt ? txt : "null"); |
| 40 | iter = json3.next_node(); |
| 41 | } |
| 42 | printf("----------------------------------------------------\r\n"); |
| 43 | |
| 44 | const std::vector<acl::json_node*>& nodes = json3.getElementsByTags(tags); |
| 45 | if (nodes.empty() == false) |
| 46 | printf(">>>%s\r\n", nodes[0]->to_string().c_str()); |
| 47 | |
| 48 | return 0; |
| 49 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…