-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Access keys when iteration with new for loop C++11 #256
Comments
Hi @MDickie, if you iterate explicitly via for (auto& element : json::iterator_wrapper(j)) {
std::cout << element.key() << " maps to " << element.value() << std::endl;
} Note that the name of this function may change in the future - when I introduced it, it seemed as if people agreed that they did not like the name, but did not propose something better 😄. So if you have an idea, I'm all ears! |
I would propose the name "object_iterator" which more closely resembles std::filesystem::directory_iterator. Edit: I see that there is such an iterator. Will take a closer look at it. |
@qis Thanks for the hint! I'll also see whether I can find some inspiration there. @MDickie Did #256 (comment) solve your problem? |
@nlohmann Yeah, thanks |
I close this issue. I'm still happy for any comments regarding the name of the |
just to share how Swift name it when using let a = ["a", "b","c"]
for (index, item) in a.enumerated() {
// ...
} it may look nicer if we define json j = {{"a", 1}, {"b", 2}, {"c", 3}};
for (auto& entry : j.object_iterator()) {
// entry.key();
// entry.value();
// ...
} |
I would expect |
Yes, the I like Python's
(in fact documentation from xml.etree.ElementTree.items()) |
Here is an example where you can access the values of the json object. However, I have no idea to access the keys.
Here is working example with stl where it is possible to access the keys:
So there is my question: Is it possible to access these keys with json in a similiar way?
The text was updated successfully, but these errors were encountered: