Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieving array elements from object type iterator. #1367

Closed
kepler425b opened this issue Nov 21, 2018 · 1 comment
Closed

Retrieving array elements from object type iterator. #1367

kepler425b opened this issue Nov 21, 2018 · 1 comment
Labels
state: needs more info the author of the issue needs to provide more details

Comments

@kepler425b
Copy link

I retrieve an array json::iterator c = itr->find("nodes"); and try to iterate through all arrays in that array (nodes is array that contains arrays):

for (json::iterator ak = c.value().begin(); ak != c.value().end(); ++c)
string id = ak[0].get<string>();

I get error, because those iterators aren't of the same type:
JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers"));

How should I iterate and access the elements from the iterated array? Couldn't find documentation on this very issue of object to array type iterator mismatch/switch.

@nlohmann
Copy link
Owner

Could you provide more information how itr is constructed? Best would be a small self-contained example.

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Nov 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs more info the author of the issue needs to provide more details
Projects
None yet
Development

No branches or pull requests

2 participants