mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
16e8db1f17
* Adding 'count_elements' method. * Actually reporting errors. * removing white space. * Removing white space again. * Adding an extra example. * Prettier. * Making the functionality more error-proof. * Avoiding exceptions. * Various fixes including extending count_elements to value types. * Various fixes. * Minor fixes. * Correcting comment. * Trimming white spaces.
21 lines
733 B
C++
21 lines
733 B
C++
#include "simdjson.h"
|
|
#include <iostream>
|
|
|
|
using namespace simdjson;
|
|
|
|
int main(void) {
|
|
ondemand::parser parser;
|
|
auto cars_json = R"( { "test":[ { "val1":1, "val2":2 }, { "val1":1, "val2":2 } ] } )"_padded;
|
|
auto doc = parser.iterate(cars_json);
|
|
auto testArray = doc.find_field("test");
|
|
#if COMPILATION_TEST_USE_FAILING_CODE
|
|
size_t count = testArray.get_array().count_elements();
|
|
std::cout << "Number of elements: " << count << std::endl;
|
|
for(simdjson_unused ondemand::object elem : testArray) {}
|
|
#else
|
|
ondemand::array a = testArray.get_array();
|
|
size_t count = a.count_elements();
|
|
std::cout << "Number of elements: " << count << std::endl;
|
|
for(simdjson_unused ondemand::object elem : a) {}
|
|
#endif
|
|
} |