diff --git a/doc/dom.md b/doc/dom.md index 1bbfed9b..def1f4ee 100644 --- a/doc/dom.md +++ b/doc/dom.md @@ -64,7 +64,7 @@ Once you have an element, you can navigate it with idiomatic C++ iterators, oper * **Extracting Values (with exceptions):** You can cast a JSON element to a native type: `double(element)` or `double x = json_element`. This works for double, uint64_t, int64_t, bool, - dom::object and dom::array. An exception is thrown if the cast is not possible. + dom::object and dom::array. An exception (`simdjson::simdjson_error`) is thrown if the cast is not possible. * **Extracting Values (without exceptions):** You can use a variant usage of `get()` with error codes to avoid exceptions. You first declare the variable of the appropriate type (`double`, `uint64_t`, `int64_t`, `bool`, `dom::object` and `dom::array`) and pass it by reference to `get()` which gives you back an error code: e.g., ```c++ diff --git a/tests/ondemand/ondemand_readme_examples.cpp b/tests/ondemand/ondemand_readme_examples.cpp index 25606dfe..ff0698e7 100644 --- a/tests/ondemand/ondemand_readme_examples.cpp +++ b/tests/ondemand/ondemand_readme_examples.cpp @@ -246,11 +246,15 @@ bool using_the_parsed_json_4() { // Parse and iterate through an array of objects for (ondemand::object points : parser.iterate(points_json)) { + // Iterating through an object, you iterate through key-value pairs (a 'field'). for (auto point : points) { + // Get the key corresponding the the field 'point'. cout << "id: " << std::string_view(point.unescaped_key()) << ": ("; - cout << point.value()["x"].get_double() << ", "; - cout << point.value()["y"].get_double() << ", "; - cout << point.value()["z"].get_int64() << endl; + // Get the value corresponding the the field 'point'. + ondemand::object xyz = point.value(); + cout << xyz["x"].get_double() << ", "; + cout << xyz["y"].get_double() << ", "; + cout << xyz["z"].get_int64() << endl; } }