| 1 | #include "stdafx.h" |
| 2 | |
| 3 | int main(void) |
| 4 | { |
| 5 | acl::json json; |
| 6 | acl::json_node& root = json.get_root(); |
| 7 | |
| 8 | |
| 9 | // ���� json ����{"1": {"1": {"1": "aa"}}} |
| 10 | root.add_child("1", true).add_child("1", true).add_text("1", "aa"); |
| 11 | printf("%s\r\n", json.to_string().c_str()); |
| 12 | |
| 13 | json.reset(); |
| 14 | |
| 15 | ////////////////////////////////////////////////////////////////////// |
| 16 | // �������ַ�������������ͬ�� json �����£� |
| 17 | // {"cmd": "add", "Para": {"xxx": "111", "yyy": "222", "zzz": true, "eee": 100}, "status": true, "length": 100} |
| 18 | |
| 19 | ////////////////////////////////////////////////////////////////////// |
| 20 | // ����һ�� |
| 21 | |
| 22 | root = json.get_root(); |
| 23 | |
| 24 | root.add_text("cmd", "add") // ���� root �ڵ���ӽڵ㲢���� root |
| 25 | .add_child("Para", true) // ���� root ���ӽڵ�(Para)������ Para |
| 26 | .add_text("xxx", "111") // ���� Para ���ӽڵ㲢���� Para |
| 27 | .add_text("yyy", "222") // ���� Para ���ӽڵ㲢���� Para |
| 28 | .add_bool("zzz", true) // ���� Para ���ӽڵ㲢���� Para |
| 29 | .add_number("eee", 100) // ���� Para ���ӽڵ㲢���� Para |
| 30 | .get_parent() // ���� Para �ĸ��ڵ�(root�ڵ�) |
| 31 | .add_bool("status", true) // ���� root �ڵ���ӽڵ� status |
| 32 | .add_number("length", 100); // ���� root �ڵ���ӽڵ� length |
| 33 | |
| 34 | printf("json1: %s\r\n", json.to_string().c_str()); |
| 35 | acl::string buf1; |
| 36 | json.build_json(buf1); |
| 37 | |
| 38 | acl::json_node* para = json.getFirstElementByTagName("Para"); |
| 39 | if (para) { |
| 40 | root.add_text("root-name", "root-value"); |
| 41 | para->get_obj()->add_text("test", "111111"); |
| 42 | printf("%s\r\n", json.to_string().c_str()); |
| 43 | } |
| 44 | |
| 45 | ////////////////////////////////////////////////////////////////////// |
| 46 | // �������� |
| 47 | |
| 48 | // ������ʹ��ǰ��Ҫ���� json ������״̬ |
| 49 | json.reset(); |
| 50 | root = json.get_root(); |
| 51 | |
| 52 | root.add_text("cmd", "add") |
| 53 | .add_child("Para", |
| 54 | json.create_node() |
| 55 | .add_text("xxx", "111") |
| 56 | .add_text("yyy", "222") |
| 57 | .add_bool("zzz", true) |
| 58 | .add_number("eee", 100)) |
| 59 | .add_bool("status", true) |
| 60 | .add_number("length", 100); |
nothing calls this directly
no test coverage detected
searching dependent graphs…