nlohmann::basic_json::at - renxiaobo27/json GitHub Wiki

reference at(size_type idx);
const_reference at(size_type idx) const;                  // 1
reference at(const object_t::key_type& key)
const_reference at(const object_t::key_type& key) const   // 2

Description

  1. Returns a reference to the element at specified index idx, with bounds checking. If idx not within the range of the container, an exception of type std::out_of_range is thrown (only works for arrays).
  2. Returns a reference to the mapped value of the element with key equivalent to key. If no such element exists, an exception of type std::out_of_range is thrown (only works for objects).

Parameters

  • idx: index of the element to return
  • key: key of the element to return

Return value

Reference to the specified value.

Complexity

  1. Constant.
  2. Logarithmic in the size of the container.

Exceptions

  1. std::runtime_error when called on a JSON container with other type than array; std::out_of_range if !(idx < size()).
  2. std::runtime_error when called on a JSON container with other type than object; std::out_of_range if the container does not have an element with the specified key.