| 4 | */ |
| 5 | |
| 6 | int 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"); |
nothing calls this directly
no test coverage detected
searching dependent graphs…