2017-07-09 09:51:38 +00:00
|
|
|
#include <iostream>
|
2017-04-21 20:07:07 +00:00
|
|
|
#include "json.hpp"
|
2015-10-16 13:23:57 +00:00
|
|
|
|
2016-01-30 19:23:14 +00:00
|
|
|
using json = nlohmann::json;
|
2015-10-16 13:23:57 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// create a JSON number
|
|
|
|
json value = 17;
|
|
|
|
|
|
|
|
// explicitly getting references
|
|
|
|
auto r1 = value.get_ref<const json::number_integer_t&>();
|
|
|
|
auto r2 = value.get_ref<json::number_integer_t&>();
|
|
|
|
|
|
|
|
// print the values
|
|
|
|
std::cout << r1 << ' ' << r2 << '\n';
|
2016-01-20 20:14:58 +00:00
|
|
|
|
2015-10-16 13:23:57 +00:00
|
|
|
// incompatible type throws exception
|
|
|
|
try
|
|
|
|
{
|
|
|
|
auto r3 = value.get_ref<json::number_float_t&>();
|
|
|
|
}
|
2017-03-08 20:03:19 +00:00
|
|
|
catch (json::type_error& ex)
|
2015-10-16 13:23:57 +00:00
|
|
|
{
|
|
|
|
std::cout << ex.what() << '\n';
|
|
|
|
}
|
|
|
|
}
|