Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
813 B
11
Indexable
Never
formats::json::Value array = formats::json::MakeArray(
    formats::json::MakeObject("name", "value1"),
    formats::json::MakeObject("name", "value2"),
    formats::json::MakeObject("name", "value3"));

std::map<std::string, const formats::json::Value&> some_map;
for (const auto& item: array) {
    auto name = item["name"].As<std::string>();
    std::cout << "before " << name << " " << formats::json::ToString(item) << std::endl;
    some_map.emplace(name, item);
}

for (const auto& item: some_map) {
    std::cout << "after  " << item.first << " " << formats::json::ToString(item.second) << std::endl;
}

// OUTPUT
before value1 {"name":"value1"}
before value2 {"name":"value2"}
before value3 {"name":"value3"}
after  value1 {"name":"value3"}
after  value2 {"name":"value3"}
after  value3 {"name":"value3"}
Leave a Comment