Skip to content

Iterating through an array of objects #2524

Answered by mayank1608
mayank1608 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @nlohmann sorry for the late reply and thanks for the quick reponse :)

Well, I want to iterate through each key value pairs of json object which is in array.
I am using iterator like this::

for (json::iterator it = jsonObj.begin(); it != jsonObj.end(); ++it) {
  for (auto & el: * it.items()) {
    std::cout << el.key() << " : " << el.value() << "\n";
  };
}

I am getting this error::
'items': is not a member of 'nlohmann::detail::iter_impl<nlohmann::basic_json<std::map,std::vector,std::st
ring,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer,std::vector<uint8_t,std::allocator<uint8_t>>>>'
'el': references must be initialized

Thanks in advance

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@nlohmann
Comment options

@mayank1608
Comment options

Answer selected by nlohmann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants