-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (60 loc) · 1.41 KB
/
Copy pathmain.cpp
File metadata and controls
68 lines (60 loc) · 1.41 KB
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
60
61
62
63
64
65
66
67
68
#include "Any.h"
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include "Json.h"
using namespace std;
int main()
{
Any a = 1;
Any b = string("hello");
Any c = vector<int>{1, 2, 3};
Any d = map<string, Any> {
{string("a"), 1},
{string("b"), string("hello")},
{string("c"), vector<Any>{1, 2, 3}}
};
cout << a.Get<int>() << endl;
cout << b.Get<string>() << endl;
cout << c.Get<vector<int>>().size() << endl;
for (auto& x : c.Get<vector<int>>())
{
cout << x << " ";
}
cout << endl;
// Json format serialization and deserialization example.
d = Json::Deserialize(Json::Serialize(d));
for (auto& [key, value] : d.Get<map<string, Any>>())
{
try
{
auto v = value.Get<int>();
cout << key << ": " << v << endl;
continue;
}
catch (std::bad_cast& e)
{
}
try
{
auto v = value.Get<string>();
cout << key << ": " << v << endl;
continue;
}
catch (std::bad_cast& e)
{
}
try
{
auto v = value.Get<vector<Any>>();
for (auto& i : v)
cout << key << ": " << i.Get<int>() << endl;
continue;
}
catch (std::bad_cast& e)
{
}
}
return 0;
}