template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
template<typename ValueType , typename std::enable_if<
detail::conjunction<
detail::negation< std::is_pointer< ValueType > >,
detail::negation< std::is_same< ValueType,
detail::json_ref<
basic_json > > >,
detail::negation< std::is_same< ValueType, typename string_t::value_type > >,
detail::negation<
detail::is_basic_json< ValueType > >,
detail::negation< std::is_same< ValueType, std::initializer_list< typename string_t::value_type > > >,
detail::is_detected_lazy< detail::get_template_function, const
basic_json_t &, ValueType > >
::value, int >
::type = 0>
JSON_EXPLICIT nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::operator ValueType |
( |
| ) |
const |
|
inline |
get a value (implicit)
Implicit type conversion between the JSON value and a compatible value. The call is realized by calling get() const.
- Template Parameters
-
ValueType | non-pointer type compatible to the JSON value, for instance int for JSON integer numbers, bool for JSON booleans, or std::vector types for JSON arrays. The character type of string_t as well as an initializer list of this type is excluded to avoid ambiguities as these types implicitly convert to std::string . |
- Returns
- copy of the JSON value, converted to type ValueType
- Exceptions
-
type_error.302 | in case passed type ValueType is incompatible to the JSON value type (e.g., the JSON value is of type boolean, but a string is requested); see example below |
@complexity Linear in the size of the JSON value.
@liveexample{The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers\, (2) A JSON array can be converted to a standard std::vector<short>
\, (3) A JSON object can be converted to C++ associative containers such as std::unordered_map<std::string\, json>
.,operator__ValueType}
- Since
- version 1.0.0
Definition at line 21113 of file json.hpp.
21114 {
21115
21116 return get<ValueType>();
21117 }