JSON for Modern C++ 3.9.1

__pad3__
accept
accept
accept
allocator_type
array
array_t
at
at
at
at
at
at
back
back
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
begin
begin
binary
binary
binary
binary
binary_t
boolean_t
cbegin
cbor_tag_handler_t
cend
clear
const_iterator
const_pointer
const_reference
const_reverse_iterator
contains
contains
count
crbegin
crend
detail::external_constructor
diff
difference_type
dump
emplace
emplace_back
empty
end
end
erase
erase
erase
erase
error_handler_t
exception
find
find
flatten
from_bson
from_bson
from_bson
from_bson
from_cbor
from_cbor
from_cbor
from_cbor
from_msgpack
from_msgpack
from_msgpack
from_msgpack
from_ubjson
from_ubjson
from_ubjson
from_ubjson
front
front
get
get
get
get
get
get
get_allocator
get_binary
get_binary
get_ptr
get_ptr
get_ref
get_ref
get_to
get_to
get_to
initializer_list_t
input_format_t
insert
insert
insert
insert
insert
insert
insert_iterator
invalid_iterator
is_array
is_binary
is_boolean
is_discarded
is_null
is_number
is_number_float
is_number_integer
is_number_unsigned
is_object
is_primitive
is_string
is_structured
items
items
iterator
iterator_wrapper
iterator_wrapper
json_pointer
json_sax_t
json_serializer
m_value
max_size
merge_patch
meta
number_float_t
number_integer_t
number_unsigned_t
object
object_comparator_t
object_t
operator value_t
operator ValueType
operator!=
operator!=
operator!=
operator+=
operator+=
operator+=
operator+=
operator<
operator<
operator<
operator<<
operator<<
operator<=
operator<=
operator<=
operator=
operator==
operator==
operator==
operator>
operator>
operator>
operator>=
operator>=
operator>=
operator>>
operator>>
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
other_error
out_of_range
parse
parse
parse
parse_error
parse_event_t
parser_callback_t
patch
pointer
push_back
push_back
push_back
push_back
rbegin
rbegin
reference
rend
rend
reverse_iterator
sax_parse
sax_parse
sax_parse
size
size_type
string_t
swap
swap
swap
swap
swap
swap
swap
to_bson
to_bson
to_bson
to_cbor
to_cbor
to_cbor
to_msgpack
to_msgpack
to_msgpack
to_ubjson
to_ubjson
to_ubjson
type
type_error
type_name
unflatten
update
update
value
value
value
value
value_t
value_type
~basic_json
| ## ◆ get() [5/6] 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 ValueTypeCV , typename ValueType = detail::uncvref_t<ValueTypeCV>, detail::enable_if_t< !detail::is_basic_json< ValueType >::value &&detail::has_from_json< basic_json_t, ValueType >::value &&!detail::has_non_default_from_json< basic_json_t, ValueType >::value, int > = 0>
ValueType nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::get | ( |  | ) | const
| inline noexcept
  Explicit type conversion between the JSON value and a compatible value which is CopyConstructible and DefaultConstructible. The value is converted by calling the json_serializer<ValueType> `from_json()` method. The function is equivalent to executing ValueType ret; JSONSerializer<ValueType>::from_json(*this, ret); return ret; This overloads is chosen if: ValueType is not basic_json, json_serializer<ValueType> has a `from_json()` method of the form `void from_json(const basic_json&, ValueType&)`, and json_serializer<ValueType> does not have a `from_json()` method of the form `ValueType from_json(const basic_json&)` Template Parameters
  ValueTypeCV | the provided value type
  ValueType | the returned value type
  Returns copy of the JSON value, converted to ValueType Exceptions
  what | json_serializer<ValueType> `from_json()` method throws
  Example 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>`. 1 #include <iostream> 2 #include <unordered_map> 3 #include <nlohmann/json.hpp> 4 5 using json = nlohmann::json; 6 7 int main() 8 { 9 // create a JSON value with different types 10 json json_types = 11 { 12 {"boolean", true}, 13 { 14 "number", { 15 {"integer", 42}, 16 {"floating-point", 17.23} 17 } 18 }, 19 {"string", "Hello, world!"}, 20 {"array", {1, 2, 3, 4, 5}}, 21 {"null", nullptr} 22 }; 23 24 // use explicit conversions 25 auto v1 = json_types["boolean"].get<bool>(); 26 auto v2 = json_types["number"]["integer"].get<int>(); 27 auto v3 = json_types["number"]["integer"].get<short>(); 28 auto v4 = json_types["number"]["floating-point"].get<float>(); 29 auto v5 = json_types["number"]["floating-point"].get<int>(); 30 auto v6 = json_types["string"].get<std::string>(); 31 auto v7 = json_types["array"].get<std::vector<short>>(); 32 auto v8 = json_types.get<std::unordered_map<std::string, json>>(); 33 34 // print the conversion results 35 std::cout << v1 << '\n'; 36 std::cout << v2 << ' ' << v3 << '\n'; 37 std::cout << v4 << ' ' << v5 << '\n'; 38 std::cout << v6 << '\n'; 39 40 for (auto i : v7) 41 { 42 std::cout << i << ' '; 43 } 44 std::cout << "\n\n"; 45 46 for (auto i : v8) 47 { 48 std::cout << i.first << ": " << i.second << '\n'; 49 } 50 } Output (play with this example online):
      1
      42 42
      17.23 17
      Hello, world!
      1 2 3 4 5

      string: "Hello, world!"
      number: {"floating-point":17.23,"integer":42}
      null: null
      boolean: true
      array: [1,2,3,4,5]
  The example code above can be translated with
      g++ -std=c++11 -Isingle_include doc/examples/get__ValueType_const.cpp -o get__ValueType_const
Since version 2.1.0 Definition at line 19432 of file json.hpp.

nlohmann::json
basic_json<> json
default JSON class
Definition: json.hpp:2940