Merge pull request #682 from simdjson/jkeiser/simplify-cars

Simplify cars example
This commit is contained in:
John Keiser 2020-04-08 10:24:01 -07:00 committed by GitHub
commit ff0b0c54b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View File

@ -80,10 +80,9 @@ auto cars_json = R"( [
{ "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
] )"_padded;
dom::parser parser;
dom::array cars = parser.parse(cars_json).get<dom::array>();
// Iterating through an array of objects
for (dom::object car : cars) {
for (dom::object car : parser.parse(cars_json)) {
// Accessing a field by name
cout << "Make/Model: " << car["make"] << "/" << car["model"] << endl;

View File

@ -28,10 +28,9 @@ void basics_dom_1() {
{ "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
] )"_padded;
dom::parser parser;
dom::array cars = parser.parse(cars_json).get<dom::array>();
// Iterating through an array of objects
for (dom::object car : cars) {
// Parse and iterate through each car
for (dom::object car : parser.parse(cars_json)) {
// Accessing a field by name
cout << "Make/Model: " << car["make"] << "/" << car["model"] << endl;
@ -61,7 +60,7 @@ void basics_dom_2() {
] )"_padded;
dom::parser parser;
dom::element cars = parser.parse(cars_json);
cout << cars.at("0/tire_pressure/1") << endl; // Prints 39.9}
cout << cars.at("0/tire_pressure/1") << endl; // Prints 39.9
}
namespace treewalk_1 {