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 >::erase |
( |
const typename object_t::key_type & |
key | ) |
|
|
inline |
remove element from a JSON object given a key
Removes elements from a JSON object with the key value key.
- Parameters
-
[in] | key | value of the elements to remove |
- Returns
- Number of elements removed. If ObjectType is the default
std::map
type, the return value will always be 0
(key was not found) or 1
(key was found).
- Postcondition
- References and iterators to the erased elements are invalidated. Other references and iterators are not affected.
- Exceptions
-
type_error.307 | when called on a type other than JSON object; example: "cannot use erase() with null" |
@complexity log(size()) + count(key)
@liveexample{The example shows the effect of erase()
.,erase__key_type}
- See also
- see erase(IteratorType) – removes the element at a given position
-
see erase(IteratorType, IteratorType) – removes the elements in the given range
-
see erase(const size_type) – removes the element from an array at the given index
- Since
- version 1.0.0
Definition at line 22134 of file json.hpp.
22135 {
22136
22138 {
22139 return m_value.object->erase(key);
22140 }
22141
22142 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
22143 }
constexpr bool is_object() const noexcept
return whether value is an object
json_value m_value
the value of the current element
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string