-
-
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
Docs - What does Json[key] return? #267
Comments
Hi @MartinNvp, there is a documentation beyond the README file. It's not great (see #248), but it contains a page for To your questions:
|
Yes I had read the operator[] docs. And then clicked through into the Reference type. which was in turn defined as value_t. The recursive definition is cool (may be obvious) but too implicit for my head ;-) I'll take a look at extending your example. But can we state that recursive deinition on the main readme.md? |
In fact, I think as you confused |
Yes it is as you say, but too subtle for a man in a rush! |
An example like this would have helped me the most: auto j_all =
R"( { )"
R"( "Pets": )"
R"( { )"
R"( "Cats": )"
R"( {"Lions":3, "Tigers":5}, )"
R"( "Dogs": )"
R"( {"Terrier":1, "Afgan":0, "Alsation":2} )"
R"( } )"
R"( } )"_json;
// Its json objects all the way down:
json j_pets = j_all["pets"];
json j_cats = j_pets["cats"];
json j_lions = j_cats["Lions"];
// or equivalently:
json j_lions2 =j_all["Pets"]["Cats"]["Lions"]; |
I don't think that such a hint is useful for many others. Nevertheless, I shall try to improve the presentation of the documentation. |
up to you. |
Background
I wanted to loop through the keys of "instruments" (without assuming the nature of the contained values).
Your main readme.md is great, but seems a tad more focus on loading than reading/querying Json. (The forms of loading are impressive/elegant.)
All the examples I could find for iterating over JSON object/map content where at the top level. Not nested.
I wanted to know what the operator[] returned. I dug into the class docs. Found json::operator[] returned some reference type.
Which did not look iterable.
Despite that observation (is it wrong?) this code works:
So I can get a JSON object at every level all the way down. Happy Surprise.
Request
Can (or should?) that readme.md docs state something like:
(not turtles ;-) )
(Hope this aint daft, new to use of your JSON, or any JSON actually.)
The text was updated successfully, but these errors were encountered: