2
0

count__keytype.c++17.cpp 535 B

1234567891011121314151617181920
  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 count()
  11. auto count_two = j_object.count("two"sv);
  12. auto count_three = j_object.count("three"sv);
  13. // print values
  14. std::cout << "number of elements with key \"two\": " << count_two << '\n';
  15. std::cout << "number of elements with key \"three\": " << count_three << '\n';
  16. }