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.

28 lines
912 B

  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_object_empty(json::value_t::object);
  12. json j_array = {1, 2, 4, 8, 16};
  13. json j_array_empty(json::value_t::array);
  14. json j_string = "Hello, world";
  15. // call back()
  16. //std::cout << j_null.back() << '\n'; // would throw
  17. std::cout << j_boolean.back() << '\n';
  18. std::cout << j_number_integer.back() << '\n';
  19. std::cout << j_number_float.back() << '\n';
  20. std::cout << j_object.back() << '\n';
  21. //std::cout << j_object_empty.back() << '\n'; // undefined behavior
  22. std::cout << j_array.back() << '\n';
  23. //std::cout << j_array_empty.back() << '\n'; // undefined behavior
  24. std::cout << j_string.back() << '\n';
  25. }