Replies: 1 comment
-
So the documentation you are quoting refers you to the fact that in some cases, you cannot access twice the same array. But in your code, you have two arrays. It is important to understand that when you do... auto person_name2 = doc["people"].at(1)["name"]; and later do... auto person_name = doc["people"].at(0)["name"]; ... you are recreating the array ( Here is a case where #include <iostream>
#define SIMDJSON_DEVELOPMENT_CHECKS 1
#include "simdjson.h"
int main() {
const char *json = R"({ "people": [ { "name": "Alice", "age": 30 }, { "name": "Bob", "age": 25 } ] })";
simdjson::ondemand::parser parser;
simdjson::padded_string jsonbuffer = simdjson::padded_string(json, std::strlen(json));
auto doc = parser.iterate(jsonbuffer);
simdjson::ondemand::array array = doc["people"];
auto person_name2 = array.at(1)["name"];
std::cout << person_name2 << std::endl;
auto person_name = array.at(0)["name"];
std::cout << person_name << std::endl;
return 0;
} In this case, a proper piece of code might look as follows: #include <iostream>
#include "simdjson.h"
int main() {
auto json = R"({ "people": [ { "name": "Alice", "age": 30 }, { "name": "Bob", "age": 25 } ] })"_padded;
simdjson::ondemand::parser parser;
auto doc = parser.iterate(json);
for(auto val : doc["people"]) {
std::cout << val["name"] << std::endl;
}
return EXIT_SUCCESS;
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I build this with
g++ -std=c++2b -o sibling sibling.cpp simdjson.cpp -g -O0
.Question> I expect to see OUT_OF_ORDER_ITERATION warning but I didn't.
What did I do wrong here?
Thank you
Beta Was this translation helpful? Give feedback.
All reactions