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

Function construct_json_from_vector

examples/src/array_examples.cpp:63–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61}
62
63void construct_json_from_vector()
64{
65 json root;
66
67 std::vector<json> addresses;
68 json address1;
69 address1["city"] = "San Francisco";
70 address1["state"] = "CA";
71 address1["zip"] = "94107";
72 address1["country"] = "USA";
73 addresses.push_back(address1);
74
75 json address2;
76 address2["city"] = "Sunnyvale";
77 address2["state"] = "CA";
78 address2["zip"] = "94085";
79 address2["country"] = "USA";
80 addresses.push_back(address2);
81
82 root["addresses"] = addresses;
83
84 std::cout << pretty_print(root) << '\n';
85
86 std::cout << "size=" << root["addresses"].size() << '\n';
87 for (std::size_t i = 0; i < root["addresses"].size(); ++i)
88 {
89 std::cout << root["addresses"][i] << '\n';
90 }
91}
92
93void add_element_to_array()
94{

Callers 1

mainFunction · 0.85

Calls 3

pretty_printFunction · 0.85
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected