Merge pull request #682 from simdjson/jkeiser/simplify-cars
Simplify cars example
This commit is contained in:
commit
ff0b0c54b7
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue