operator__ValueType.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 a JSON value with different types
00009     json json_types =
00010     {
00011         {"boolean", true},
00012         {
00013             "number", {
00014                 {"integer", 42},
00015                 {"floating-point", 17.23}
00016             }
00017         },
00018         {"string", "Hello, world!"},
00019         {"array", {1, 2, 3, 4, 5}},
00020         {"null", nullptr}
00021     };
00022 
00023     // use implicit conversions
00024     bool v1 = json_types["boolean"];
00025     int v2 = json_types["number"]["integer"];
00026     short v3 = json_types["number"]["integer"];
00027     float v4 = json_types["number"]["floating-point"];
00028     int v5 = json_types["number"]["floating-point"];
00029     std::string v6 = json_types["string"];
00030     std::vector<short> v7 = json_types["array"];
00031     std::unordered_map<std::string, json> v8 = json_types;
00032 
00033     // print the conversion results
00034     std::cout << v1 << '\n';
00035     std::cout << v2 << ' ' << v3 << '\n';
00036     std::cout << v4 << ' ' << v5 << '\n';
00037     std::cout << v6 << '\n';
00038 
00039     for (auto i : v7)
00040     {
00041         std::cout << i << ' ';
00042     }
00043     std::cout << "\n\n";
00044 
00045     for (auto i : v8)
00046     {
00047         std::cout << i.first << ": " << i.second << '\n';
00048     }
00049 }


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