MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / array_example1

Function array_example1

examples/src/array_examples.cpp:13–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11using namespace jsoncons;
12
13void array_example1()
14{
15 {
16 std::vector<int> v = {1,2,3,4};
17 json a(v);
18 std::cout << a << '\n';
19 }
20 {
21 json j(json_array_arg, {1,true,"last"});
22 auto d = j.as<std::deque<std::string>>();
23 for (auto x : d)
24 {
25 std::cout << x << '\n';
26 }
27 }
28 {
29 std::map<std::string,int> m = {{"one",1},{"two",2},{"three",3}};
30 json j(m);
31 std::cout << j << '\n';
32 }
33 {
34 json j;
35 j["one"] = 1;
36 j["two"] = 2;
37 j["three"] = 3;
38
39 auto um = j.as<std::unordered_map<std::string,int>>();
40 for (const auto& x : um)
41 {
42 std::cout << x.first << "=" << x.second << '\n';
43 }
44 }
45}
46
47void accessing_a_json_value_as_a_vector()
48{

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected