find__keytype.c++17.cpp 617 B

12345678910111213141516171819202122
  1. #include <iostream>
  2. #include <string_view>
  3. #include <nlohmann/json.hpp>
  4. using namespace std::string_view_literals;
  5. using json = nlohmann::json;
  6. int main()
  7. {
  8. // create a JSON object
  9. json j_object = {{"one", 1}, {"two", 2}};
  10. // call find
  11. auto it_two = j_object.find("two"sv);
  12. auto it_three = j_object.find("three"sv);
  13. // print values
  14. std::cout << std::boolalpha;
  15. std::cout << "\"two\" was found: " << (it_two != j_object.end()) << '\n';
  16. std::cout << "value at key \"two\": " << *it_two << '\n';
  17. std::cout << "\"three\" was found: " << (it_three != j_object.end()) << '\n';
  18. }