mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
iterating over a simdjson_result<padded_string> (#2614)
This commit is contained in:
@@ -764,7 +764,7 @@ bool basics_1() {
|
||||
TEST_START();
|
||||
|
||||
ondemand::parser parser;
|
||||
auto json = padded_string::load("twitter.json");
|
||||
auto json = padded_string::load("twitter.json"); // this is a simdjson_result<padded_string>
|
||||
ondemand::document doc = parser.iterate(json); // load and parse a file
|
||||
|
||||
simdjson_unused auto unused_doc = doc.get_object();
|
||||
|
||||
@@ -20,6 +20,26 @@ namespace twitter_tests {
|
||||
TEST_SUCCEED();
|
||||
}
|
||||
#if SIMDJSON_EXCEPTIONS
|
||||
bool twitter_result_example() {
|
||||
TEST_START();
|
||||
simdjson_result<padded_string> json = padded_string::load(TWITTER_JSON);
|
||||
ondemand::parser parser;
|
||||
auto doc = parser.iterate(json);
|
||||
for (ondemand::object tweet : doc["statuses"]) {
|
||||
uint64_t id = tweet["id"];
|
||||
std::string_view text = tweet["text"];
|
||||
std::string_view screen_name = tweet["user"]["screen_name"];
|
||||
uint64_t retweets = tweet["retweet_count"];
|
||||
uint64_t favorites = tweet["favorite_count"];
|
||||
(void) id;
|
||||
(void) text;
|
||||
(void) retweets;
|
||||
(void) favorites;
|
||||
(void) screen_name;
|
||||
}
|
||||
TEST_SUCCEED();
|
||||
}
|
||||
|
||||
bool twitter_example() {
|
||||
TEST_START();
|
||||
padded_string json;
|
||||
@@ -182,6 +202,7 @@ namespace twitter_tests {
|
||||
twitter_default_profile() &&
|
||||
twitter_image_sizes() &&
|
||||
#if SIMDJSON_EXCEPTIONS
|
||||
twitter_result_example() &&
|
||||
twitter_count_exception() &&
|
||||
twitter_example() &&
|
||||
twitter_default_profile_exception() &&
|
||||
|
||||
Reference in New Issue
Block a user