basic_json__CompatibleObjectType.cpp
Go to the documentation of this file.
00001 #include <json.hpp>
00002 #include <unordered_map>
00003 
00004 using json = nlohmann::json;
00005 
00006 int main()
00007 {
00008     // create an object from std::map
00009     std::map<std::string, int> c_map
00010     {
00011         {"one", 1}, {"two", 2}, {"three", 3}
00012     };
00013     json j_map(c_map);
00014 
00015     // create an object from std::unordered_map
00016     std::unordered_map<const char*, double> c_umap
00017     {
00018         {"one", 1.2}, {"two", 2.3}, {"three", 3.4}
00019     };
00020     json j_umap(c_umap);
00021 
00022     // create an object from std::multimap
00023     std::multimap<std::string, bool> c_mmap
00024     {
00025         {"one", true}, {"two", true}, {"three", false}, {"three", true}
00026     };
00027     json j_mmap(c_mmap); // only one entry for key "three" is used
00028 
00029     // create an object from std::unordered_multimap
00030     std::unordered_multimap<std::string, bool> c_ummap
00031     {
00032         {"one", true}, {"two", true}, {"three", false}, {"three", true}
00033     };
00034     json j_ummap(c_ummap); // only one entry for key "three" is used
00035 
00036     // serialize the JSON objects
00037     std::cout << j_map << '\n';
00038     std::cout << j_umap << '\n';
00039     std::cout << j_mmap << '\n';
00040     std::cout << j_ummap << '\n';
00041 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:01