You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.1 KiB

  1. #include <json.hpp>
  2. using json = nlohmann::json;
  3. int main()
  4. {
  5. // create JSON values
  6. json j_null;
  7. json j_boolean = true;
  8. json j_number_integer = 17;
  9. json j_number_float = 23.42;
  10. json j_object = {{"one", 1}, {"two", 2}};
  11. json j_array = {1, 2, 4, 8, 16};
  12. json j_string = "Hello, world";
  13. // call operator value_t()
  14. json::value_t t_null = j_null;
  15. json::value_t t_boolean = j_boolean;
  16. json::value_t t_number_integer = j_number_integer;
  17. json::value_t t_number_float = j_number_float;
  18. json::value_t t_object = j_object;
  19. json::value_t t_array = j_array;
  20. json::value_t t_string = j_string;
  21. // print types
  22. std::cout << std::boolalpha;
  23. std::cout << (t_null == json::value_t::null) << '\n';
  24. std::cout << (t_boolean == json::value_t::boolean) << '\n';
  25. std::cout << (t_number_integer == json::value_t::number_integer) << '\n';
  26. std::cout << (t_number_float == json::value_t::number_float) << '\n';
  27. std::cout << (t_object == json::value_t::object) << '\n';
  28. std::cout << (t_array == json::value_t::array) << '\n';
  29. std::cout << (t_string == json::value_t::string) << '\n';
  30. }