at__object_t_key_type.cpp
Go to the documentation of this file.
00001 #include <json.hpp>
00002 
00003 using json = nlohmann::json;
00004 
00005 int main()
00006 {
00007     // create JSON object
00008     json object =
00009     {
00010         {"the good", "il buono"},
00011         {"the bad", "il cativo"},
00012         {"the ugly", "il brutto"}
00013     };
00014 
00015     // output element with key "the ugly"
00016     std::cout << object.at("the ugly") << '\n';
00017 
00018     // change element with key "the bad"
00019     object.at("the bad") = "il cattivo";
00020 
00021     // output changed array
00022     std::cout << object << '\n';
00023 
00024     // try to write at a nonexisting key
00025     try
00026     {
00027         object.at("the fast") = "il rapido";
00028     }
00029     catch (std::out_of_range& e)
00030     {
00031         std::cout << "out of range: " << e.what() << '\n';
00032     }
00033 }


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