/
test_json.cpp
59 lines (48 loc) · 1.84 KB
/
test_json.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "MQueue/parse_json.h"
#include <iostream>
using std::cout;
using std::endl;
int main() {
ParseJsonObj myJson("../config/testJson.json");
vector<map<string, string> > result_array = myJson.GetChildDataArray("Config.Server.Connection");
for (auto key_value_map : result_array) {
for (auto the_pair : key_value_map) {
cout << the_pair.first << "---" << the_pair.second << endl;
}
}
result_array = myJson.GetChildDataArray("Config.Client.Connection");
for (auto key_value_map : result_array) {
for (auto the_pair : key_value_map) {
cout << the_pair.first << "---" << the_pair.second << endl;
}
}
cout << "=========" << endl;
cout << myJson.GetChildData("hello.MysqlConnection.IP") << endl;
cout << "=========" << endl;
map<string, string> key_value_map = myJson.GetChildDataMap("hello.MysqlConnection");
for (auto the_pair : key_value_map) {
cout << the_pair.first << "---" << the_pair.second << endl;
}
//==================== put ====================
myJson.PutChildData("testPut", "testPut");
myJson.PutChildData("testPut2", "testPut2");
map<string, string> my_map;
my_map.insert(make_pair("IP","0.0.0.1"));
my_map.insert(make_pair("Port","1"));
my_map.insert(make_pair("max_con","1"));
myJson.PutChildDataMap("hello.TestConnection", my_map);
map<string, string> the_map;
the_map.insert(make_pair("IP", "0.0.0.1"));
the_map.insert(make_pair("Port", "0"));
the_map.insert(make_pair("Backlog", "1"));
map<string, string> hello_map;
hello_map.insert(make_pair("IP", "0.0.0.1"));
hello_map.insert(make_pair("Port", "0"));
hello_map.insert(make_pair("Backlog", "1"));
vector<map<string, string> > the_vector;
the_vector.push_back(the_map);
the_vector.push_back(hello_map);
myJson.PutChildDataArray("Config.Server.Nee", the_vector);
myJson.SaveConfig();
return 0;
}