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
- Returns a reference to the element at specified index
idx, with bounds checking. Ifidxnot within the range of the container, an exception of typestd::out_of_rangeis thrown (only works for arrays). - Returns a reference to the mapped value of the element with key equivalent to
key. If no such element exists, an exception of typestd::out_of_rangeis thrown (only works for objects).
Parameters
idx: index of the element to returnkey: key of the element to return
Return value
Reference to the specified value.
Complexity
- Constant.
- Logarithmic in the size of the container.
Exceptions
std::runtime_errorwhen called on a JSON container with other type thanarray;std::out_of_rangeif!(idx < size()).std::runtime_errorwhen called on a JSON container with other type thanobject;std::out_of_rangeif the container does not have an element with the specified key.