basic_json__value.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 a JSON object with different entry types
00008     json j =
00009     {
00010         {"integer", 1},
00011         {"floating", 42.23},
00012         {"string", "hello world"},
00013         {"boolean", true},
00014         {"object", {{"key1", 1}, {"key2", 2}}},
00015         {"array", {1, 2, 3}}
00016     };
00017 
00018     // access existing values
00019     int v_integer = j.value("integer", 0);
00020     double v_floating = j.value("floating", 47.11);
00021 
00022     // access nonexisting values and rely on default value
00023     std::string v_string = j.value("nonexisting", "oops");
00024     bool v_boolean = j.value("nonexisting", false);
00025 
00026     // output values
00027     std::cout << std::boolalpha << v_integer << " " << v_floating
00028               << " " << v_string << " " << v_boolean << "\n";
00029 }


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