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.

26 lines
545 B

  1. #include <json.hpp>
  2. using json = nlohmann::json;
  3. int main()
  4. {
  5. // create a JSON number
  6. json value = 17;
  7. // explicitly getting references
  8. auto r1 = value.get_ref<const json::number_integer_t&>();
  9. auto r2 = value.get_ref<json::number_integer_t&>();
  10. // print the values
  11. std::cout << r1 << ' ' << r2 << '\n';
  12. // incompatible type throws exception
  13. try
  14. {
  15. auto r3 = value.get_ref<json::number_float_t&>();
  16. }
  17. catch (std::domain_error& ex)
  18. {
  19. std::cout << ex.what() << '\n';
  20. }
  21. }