| 35 | } |
| 36 | #include <iostream> |
| 37 | int main() |
| 38 | { |
| 39 | #if 1 |
| 40 | const char* sss = |
| 41 | "[{\"DataKey1\": \"BindRule\", \"DataValue\": {\"waittime\": \"7\"}, \"null_key\": \"null\"},\r\n" |
| 42 | "{\"DataKey2\": \"BindRule\", \"DataValue\": {\"waittime\": \"7\"}, \"null_key\": \"null\"},\r\n" |
| 43 | "{\"member\": [25, 26, 27, 28, 29, true, false]},\r\n" |
| 44 | "{\"max_uint64\": 18446744073709551615},\r\n" |
| 45 | "[\"string\", true, false, 100, 200, 300, null, null],\r\n" |
| 46 | "{\"hello world\": true, \"name\": null, \"age\": 25}]\r\n" |
| 47 | "{\"hello\" : \"world\"} \r\n"; |
| 48 | #else |
| 49 | const char* sss = "{\"name\": \"100\"}"; |
| 50 | #endif |
| 51 | |
| 52 | acl::json json; |
| 53 | const char* ptr = json.update(sss); |
| 54 | |
| 55 | printf("-------------------------------------------------------\r\n"); |
| 56 | |
| 57 | printf("%s\r\n", sss); |
| 58 | |
| 59 | printf("-------------------------------------------------------\r\n"); |
| 60 | |
| 61 | printf("json finish: %s, left char: %s\r\n", |
| 62 | json.finish() ? "yes" : "no", ptr); |
| 63 | |
| 64 | printf(">>>to string: %s\r\n", json.to_string().c_str()); |
| 65 | |
| 66 | const char* ss = |
| 67 | "[{\"DataKey1\": \"BindRule\", \"DataValue\": {\"waittime\": \"7\"}, \"null_key\": \"null\"}, " |
| 68 | "{\"DataKey2\": \"BindRule\", \"DataValue\": {\"waittime\": \"7\"}, \"null_key\": \"null\"}, " |
| 69 | "{\"member\": [25, 26, 27, 28, 29, true, false]}, " |
| 70 | "{\"max_uint64\": 18446744073709551615 }, " |
| 71 | "[\"string\", true, false, 100, 200, 300, null, null], " |
| 72 | "{\"hello world\": true, \"name\": null, \"age\": 25}]"; |
| 73 | |
| 74 | printf("-------------------------------------------------------\r\n"); |
| 75 | |
| 76 | acl::string buf1(json.to_string()), buf2(ss); |
| 77 | |
| 78 | buf1.trim_space().trim_line(); |
| 79 | buf2.trim_space().trim_line(); |
| 80 | |
| 81 | if (buf1 == buf2) |
| 82 | printf("All OK\r\n\r\n"); |
| 83 | else |
| 84 | { |
| 85 | printf("Error\r\n"); |
| 86 | printf("-------------------------------------------------------\r\n"); |
| 87 | printf("%s\r\n", ss); |
| 88 | printf("-------------------------------------------------------\r\n"); |
| 89 | printf("%s\r\n", json.to_string().c_str()); |
| 90 | printf("\r\n"); |
| 91 | exit (1); |
| 92 | } |
| 93 | |
| 94 | |