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>>
size_type nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::size |
( |
| ) |
const |
|
inlinenoexcept |
returns the number of elements
Returns the number of elements in a JSON value.
- Returns
- The return value depends on the different types and is defined as follows:
Value type | return value |
null | 0 |
boolean | 1 |
string | 1 |
number | 1 |
binary | 1 |
object | result of function object_t::size() |
array | result of function array_t::size() |
@liveexample{The following code calls size()
on the different value types.,size}
@complexity Constant, as long as array_t and object_t satisfy the Container concept; that is, their size() functions have constant complexity.
@iterators No changes.
@exceptionsafety No-throw guarantee: this function never throws exceptions.
- Note
- This function does not return the length of a string stored as JSON value - it returns the number of elements in the JSON value which is 1 in the case of a string.
@requirement This function helps basic_json
satisfying the Container requirements:
- The complexity is constant.
- Has the semantics of
std::distance(begin(), end())
.
- See also
- see empty() – checks whether the container is empty
-
see max_size() – returns the maximal number of elements
- Since
- version 1.0.0
Definition at line 22912 of file json.hpp.
22913 {
22914 switch (m_type)
22915 {
22917 {
22918
22919 return 0;
22920 }
22921
22923 {
22924
22925 return m_value.array->size();
22926 }
22927
22929 {
22930
22931 return m_value.object->size();
22932 }
22933
22941 default:
22942 {
22943
22944 return 1;
22945 }
22946 }
22947 }
json_value m_value
the value of the current element
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)